Skip to content

Commit 55e1265

Browse files
committed
v1
0 parents  commit 55e1265

File tree

179 files changed

+11848
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+11848
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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@v5
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 "client_exists=true" >> $GITHUB_OUTPUT
49+
else
50+
echo "client_exists=false" >> $GITHUB_OUTPUT
51+
fi
52+
53+
- name: Setup Node.js
54+
if: steps.check_client.outputs.client_exists == 'true'
55+
uses: actions/setup-node@v3
56+
with:
57+
node-version: 24
58+
59+
- name: Install npm dependencies
60+
if: steps.check_client.outputs.client_exists == 'true'
61+
working-directory: ./MyApp.Client
62+
run: npm install
63+
64+
- name: Install x tool
65+
run: dotnet tool install -g x
66+
67+
- name: Apply Production AppSettings
68+
env:
69+
APPSETTINGS_PATCH: ${{ secrets.APPSETTINGS_PATCH }}
70+
if: env.APPSETTINGS_PATCH != null
71+
working-directory: ./MyApp
72+
run: |
73+
cat <<EOF >> appsettings.json.patch
74+
${{ secrets.APPSETTINGS_PATCH }}
75+
EOF
76+
x patch appsettings.json.patch
77+
78+
- name: Login to GitHub Container Registry
79+
uses: docker/login-action@v3
80+
with:
81+
registry: ghcr.io
82+
username: ${{ env.KAMAL_REGISTRY_USERNAME }}
83+
password: ${{ env.KAMAL_REGISTRY_PASSWORD }}
84+
85+
- name: Setup .NET
86+
uses: actions/setup-dotnet@v5
87+
with:
88+
dotnet-version: 8.0.x
89+
90+
- name: Build and push Docker image
91+
env:
92+
SERVICESTACK_LICENSE: ${{ secrets.SERVICESTACK_LICENSE }}
93+
run: |
94+
dotnet publish --os linux --arch x64 -c Release -p:ContainerRepository=${{ env.image_repository_name }} -p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest -p:ContainerPort=80 -p:ContainerEnvironmentVariable="SERVICESTACK_LICENSE=${{ secrets.SERVICESTACK_LICENSE }}"

.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@v5
15+
16+
- name: Setup dotnet
17+
uses: actions/setup-dotnet@v5
18+
with:
19+
dotnet-version: 8.0.x
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: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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@v5
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/[email protected]
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: |
80+
kamal server bootstrap
81+
82+
- name: Check if first run and execute kamal app boot if necessary
83+
run: |
84+
FIRST_RUN_FILE=".${{ env.repository_name }}"
85+
if ! kamal server exec --no-interactive -q "test -f $FIRST_RUN_FILE"; then
86+
kamal server exec --no-interactive -q "touch $FIRST_RUN_FILE" || true
87+
kamal deploy -q -P --version latest || true
88+
else
89+
echo "Not first run, skipping kamal app boot"
90+
fi
91+
92+
- name: Ensure file permissions
93+
run: |
94+
kamal server exec --no-interactive "mkdir -p /opt/docker/${{ env.repository_name }}/App_Data && chown -R 1654:1654 /opt/docker/${{ env.repository_name }}"
95+
96+
- name: Migration
97+
if: env.HAS_MIGRATIONS == 'true'
98+
run: |
99+
kamal server exec --no-interactive 'echo "${{ env.KAMAL_REGISTRY_PASSWORD }}" | docker login ghcr.io -u ${{ env.KAMAL_REGISTRY_USERNAME }} --password-stdin'
100+
kamal server exec --no-interactive "docker pull ghcr.io/${{ env.image_repository_name }}:latest || true"
101+
kamal app exec --no-reuse --no-interactive --version=latest "--AppTasks=migrate"
102+
103+
- name: Deploy with Kamal
104+
run: |
105+
kamal lock release -v
106+
kamal server exec --no-interactive 'echo "${{ env.KAMAL_REGISTRY_PASSWORD }}" | docker login ghcr.io -u ${{ env.KAMAL_REGISTRY_USERNAME }} --password-stdin'
107+
kamal deploy -P --version latest

0 commit comments

Comments
 (0)