Skip to content

Commit 9bfb943

Browse files
authored
Merge pull request #2 from NetCoreTemplates/feature/kamal-deployment
Feature/kamal deployment
2 parents e6e6a2b + 2aaa1c8 commit 9bfb943

File tree

15 files changed

+490
-314
lines changed

15 files changed

+490
-314
lines changed

.deploy/docker-compose.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.deploy/nginx-proxy-compose.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.

.github/workflows/README.md

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
env:
16+
DOCKER_BUILDKIT: 1
17+
KAMAL_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
18+
KAMAL_REGISTRY_USERNAME: ${{ github.actor }}
19+
20+
jobs:
21+
build-container:
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 [ -n "${{ secrets.APPSETTINGS_PATCH }}" ]; then
35+
echo "HAS_APPSETTINGS_PATCH=true" >> $GITHUB_ENV
36+
else
37+
echo "HAS_APPSETTINGS_PATCH=false" >> $GITHUB_ENV
38+
fi
39+
if [ -n "${{ secrets.KAMAL_DEPLOY_IP }}" ]; then
40+
echo "HAS_DEPLOY_ACTION=true" >> $GITHUB_ENV
41+
else
42+
echo "HAS_DEPLOY_ACTION=false" >> $GITHUB_ENV
43+
fi
44+
45+
# This step is for the deployment of the templates only, safe to delete
46+
- name: Modify csproj for template deploy
47+
if: env.HAS_DEPLOY_ACTION == 'true'
48+
run: |
49+
sed -i 's#<ContainerLabel Include="service" Value="my-app" />#<ContainerLabel Include="service" Value="${{ env.repository_name_lower }}" />#g' MyApp/MyApp.csproj
50+
51+
- name: Check for Client directory and package.json
52+
id: check_client
53+
run: |
54+
if [ -d "MyApp.Client" ] && [ -f "MyApp.Client/package.json" ]; then
55+
echo "client_exists=true" >> $GITHUB_OUTPUT
56+
else
57+
echo "client_exists=false" >> $GITHUB_OUTPUT
58+
fi
59+
60+
- name: Setup Node.js
61+
if: steps.check_client.outputs.client_exists == 'true'
62+
uses: actions/setup-node@v3
63+
with:
64+
node-version: 22
65+
66+
- name: Install npm dependencies
67+
if: steps.check_client.outputs.client_exists == 'true'
68+
working-directory: ./MyApp.Client
69+
run: npm install
70+
71+
- name: Install x tool
72+
run: dotnet tool install -g x
73+
74+
- name: Apply Production AppSettings
75+
if: env.HAS_APPSETTINGS_PATCH == 'true'
76+
working-directory: ./MyApp
77+
run: |
78+
cat <<EOF >> appsettings.json.patch
79+
${{ secrets.APPSETTINGS_PATCH }}
80+
EOF
81+
x patch appsettings.json.patch
82+
83+
- name: Login to GitHub Container Registry
84+
uses: docker/login-action@v3
85+
with:
86+
registry: ghcr.io
87+
username: ${{ env.KAMAL_REGISTRY_USERNAME }}
88+
password: ${{ env.KAMAL_REGISTRY_PASSWORD }}
89+
90+
- name: Setup .NET
91+
uses: actions/setup-dotnet@v3
92+
with:
93+
dotnet-version: '8.0'
94+
95+
- name: Build and push Docker image
96+
run: |
97+
dotnet publish --os linux --arch x64 -c Release -p:ContainerRepository=${{ env.image_repository_name }} -p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest -p:ContainerPort=80

0 commit comments

Comments
 (0)