Skip to content

Commit b557d97

Browse files
committed
first commit
0 parents  commit b557d97

344 files changed

Lines changed: 257862 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Build Container
2+
permissions:
3+
packages: write
4+
contents: write
5+
on:
6+
workflow_run:
7+
workflows: ["Build"]
8+
types:
9+
- completed
10+
branches:
11+
- main
12+
- master
13+
workflow_dispatch:
14+
15+
# Only update envs here if you need to change them for this workflow
16+
env:
17+
DOCKER_BUILDKIT: 1
18+
KAMAL_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
19+
KAMAL_REGISTRY_USERNAME: ${{ github.actor }}
20+
21+
jobs:
22+
build-container:
23+
runs-on: ubuntu-latest
24+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v3
28+
29+
- name: Set up environment variables
30+
run: |
31+
echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
32+
echo "repository_name=$(echo ${{ github.repository }} | cut -d '/' -f 2)" >> $GITHUB_ENV
33+
echo "repository_name_lower=$(echo ${{ github.repository }} | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
34+
echo "org_name=$(echo ${{ github.repository }} | cut -d '/' -f 1)" >> $GITHUB_ENV
35+
36+
# This step is for the deployment of the templates only, safe to delete
37+
- name: Modify csproj for template deploy
38+
env:
39+
KAMAL_DEPLOY_IP: ${{ secrets.KAMAL_DEPLOY_IP }}
40+
if: env.KAMAL_DEPLOY_IP != null
41+
run: |
42+
sed -i 's#<ContainerLabel Include="service" Value="my-app" />#<ContainerLabel Include="service" Value="${{ env.repository_name_lower }}" />#g' MyApp/MyApp.csproj
43+
44+
- name: Check for Client directory and package.json
45+
id: check_client
46+
run: |
47+
if [ -d "MyApp.Client" ] && [ -f "MyApp.Client/package.json" ]; then
48+
echo "requires_npm=true" >> $GITHUB_OUTPUT
49+
fi
50+
51+
- name: Setup Node.js
52+
if: steps.check_client.outputs.requires_npm == 'true'
53+
uses: actions/setup-node@v3
54+
with:
55+
node-version: 22
56+
57+
- name: Install npm dependencies
58+
if: steps.check_client.outputs.requires_npm == 'true'
59+
working-directory: ./MyApp.Client
60+
run: npm install
61+
62+
- name: Install tailwindcss
63+
run: |
64+
mkdir -p /home/runner/.local/bin
65+
curl -o "/home/runner/.local/bin/tailwindcss" -L "https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64"
66+
chmod +x /home/runner/.local/bin/tailwindcss
67+
68+
- name: Install x tool
69+
run: dotnet tool install -g x
70+
71+
- name: Apply Production AppSettings
72+
env:
73+
APPSETTINGS_PATCH: ${{ secrets.APPSETTINGS_PATCH }}
74+
if: env.APPSETTINGS_PATCH != null
75+
working-directory: ./MyApp
76+
run: |
77+
cat <<EOF >> appsettings.json.patch
78+
${{ secrets.APPSETTINGS_PATCH }}
79+
EOF
80+
x patch appsettings.json.patch
81+
82+
- name: Login to GitHub Container Registry
83+
uses: docker/login-action@v3
84+
with:
85+
registry: ghcr.io
86+
username: ${{ env.KAMAL_REGISTRY_USERNAME }}
87+
password: ${{ env.KAMAL_REGISTRY_PASSWORD }}
88+
89+
- name: Setup .NET
90+
uses: actions/setup-dotnet@v3
91+
with:
92+
dotnet-version: '8.0'
93+
94+
- name: Build and push Docker image
95+
run: |
96+
dotnet publish --os linux --arch x64 -c Release -p:ContainerRepository=${{ env.image_repository_name }} -p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest -p:ContainerPort=80

.github/workflows/build.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Build
2+
3+
on:
4+
pull_request: {}
5+
push:
6+
branches:
7+
- '**' # matches every branch
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: checkout
14+
uses: actions/checkout@v3
15+
16+
- name: Setup dotnet
17+
uses: actions/setup-dotnet@v3
18+
with:
19+
dotnet-version: '8.*'
20+
21+
- name: build
22+
run: dotnet build
23+
working-directory: .
24+
25+
- name: test
26+
run: |
27+
dotnet test
28+
if [ $? -eq 0 ]; then
29+
echo TESTS PASSED
30+
else
31+
echo TESTS FAILED
32+
exit 1
33+
fi
34+
working-directory: ./MyApp.Tests
35+

.github/workflows/release.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Release
2+
permissions:
3+
packages: write
4+
contents: write
5+
on:
6+
workflow_run:
7+
workflows: ["Build Container"]
8+
types:
9+
- completed
10+
branches:
11+
- main
12+
- master
13+
workflow_dispatch:
14+
15+
env:
16+
DOCKER_BUILDKIT: 1
17+
KAMAL_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
18+
KAMAL_REGISTRY_USERNAME: ${{ github.actor }}
19+
20+
jobs:
21+
release:
22+
runs-on: ubuntu-latest
23+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v3
27+
28+
- name: Set up environment variables
29+
run: |
30+
echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
31+
echo "repository_name=$(echo ${{ github.repository }} | cut -d '/' -f 2)" >> $GITHUB_ENV
32+
echo "repository_name_lower=$(echo ${{ github.repository }} | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
33+
echo "org_name=$(echo ${{ github.repository }} | cut -d '/' -f 1)" >> $GITHUB_ENV
34+
if find . -maxdepth 2 -type f -name "Configure.Db.Migrations.cs" | grep -q .; then
35+
echo "HAS_MIGRATIONS=true" >> $GITHUB_ENV
36+
else
37+
echo "HAS_MIGRATIONS=false" >> $GITHUB_ENV
38+
fi
39+
40+
# This step is for the deployment of the templates only, safe to delete
41+
- name: Modify deploy.yml
42+
env:
43+
KAMAL_DEPLOY_IP: ${{ secrets.KAMAL_DEPLOY_IP }}
44+
if: env.KAMAL_DEPLOY_IP != null
45+
run: |
46+
sed -i "s/service: my-app/service: ${{ env.repository_name_lower }}/g" config/deploy.yml
47+
sed -i "s#image: my-user/myapp#image: ${{ env.image_repository_name }}#g" config/deploy.yml
48+
sed -i "s/- 192.168.0.1/- ${{ secrets.KAMAL_DEPLOY_IP }}/g" config/deploy.yml
49+
sed -i "s/host: my-app.example.com/host: ${{ secrets.KAMAL_DEPLOY_HOST }}/g" config/deploy.yml
50+
sed -i "s/MyApp/${{ env.repository_name }}/g" config/deploy.yml
51+
52+
- name: Login to GitHub Container Registry
53+
uses: docker/login-action@v3
54+
with:
55+
registry: ghcr.io
56+
username: ${{ env.KAMAL_REGISTRY_USERNAME }}
57+
password: ${{ env.KAMAL_REGISTRY_PASSWORD }}
58+
59+
- name: Set up SSH key
60+
uses: webfactory/ssh-agent@v0.9.0
61+
with:
62+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
63+
64+
- name: Setup Ruby
65+
uses: ruby/setup-ruby@v1
66+
with:
67+
ruby-version: 3.3.0
68+
bundler-cache: true
69+
70+
- name: Install Kamal
71+
run: gem install kamal -v 2.3.0
72+
73+
- name: Set up Docker Buildx
74+
uses: docker/setup-buildx-action@v3
75+
with:
76+
driver-opts: image=moby/buildkit:master
77+
78+
- name: Kamal bootstrap
79+
run: kamal server bootstrap
80+
81+
- name: Check if first run and execute kamal app boot if necessary
82+
run: |
83+
FIRST_RUN_FILE=".${{ env.repository_name }}"
84+
if ! kamal server exec --no-interactive -q "test -f $FIRST_RUN_FILE"; then
85+
kamal server exec --no-interactive -q "touch $FIRST_RUN_FILE" || true
86+
kamal deploy -q -P --version latest || true
87+
else
88+
echo "Not first run, skipping kamal app boot"
89+
fi
90+
91+
- name: Ensure file permissions
92+
run: |
93+
kamal server exec --no-interactive "mkdir -p /opt/docker/${{ env.repository_name }}/App_Data && chown -R 1654:1654 /opt/docker/${{ env.repository_name }}"
94+
95+
- name: Migration
96+
if: env.HAS_MIGRATIONS == 'true'
97+
run: |
98+
kamal server exec --no-interactive 'echo "${{ env.KAMAL_REGISTRY_PASSWORD }}" | docker login ghcr.io -u ${{ env.KAMAL_REGISTRY_USERNAME }} --password-stdin'
99+
kamal server exec --no-interactive "docker pull ghcr.io/${{ env.image_repository_name }}:latest || true"
100+
kamal app exec --no-reuse --no-interactive --version=latest "--AppTasks=migrate"
101+
102+
- name: Deploy with Kamal
103+
run: |
104+
kamal lock release -v
105+
kamal deploy -P --version latest

0 commit comments

Comments
 (0)