generated from NetCoreTemplates/blazor-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
name: Release and Deploy | ||
name: Release | ||
permissions: | ||
packages: write | ||
contents: write | ||
on: | ||
workflow_run: | ||
workflows: ["Build"] | ||
workflows: ["Build Container"] | ||
types: | ||
- completed | ||
branches: | ||
- main | ||
- master | ||
workflow_dispatch: | ||
|
||
# Only update envs here if you need to change them for this workflow | ||
env: | ||
DOCKER_BUILDKIT: 1 | ||
KAMAL_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | ||
KAMAL_REGISTRY_USERNAME: ${{ github.actor }} | ||
REDDIT_CLIENT: ${{ secrets.REDDIT_CLIENT }} | ||
REDDIT_SECRET: ${{ secrets.REDDIT_SECRET }} | ||
R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }} | ||
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} | ||
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} | ||
|
||
|
||
# Standard steps for building and deploying a .NET app via Kamal | ||
jobs: | ||
build-and-deploy: | ||
release: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
@@ -33,48 +29,36 @@ jobs: | |
run: | | ||
echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | ||
echo "repository_name=$(echo ${{ github.repository }} | cut -d '/' -f 2)" >> $GITHUB_ENV | ||
echo "repository_name_lower=$(echo ${{ github.repository }} | cut -d '/' -f 2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | ||
echo "org_name=$(echo ${{ github.repository }} | cut -d '/' -f 1)" >> $GITHUB_ENV | ||
if find . -maxdepth 2 -type f -name "Configure.Db.Migrations.cs" | grep -q .; then | ||
echo "HAS_MIGRATIONS=true" >> $GITHUB_ENV | ||
else | ||
echo "HAS_MIGRATIONS=false" >> $GITHUB_ENV | ||
fi | ||
if [ -n "${{ secrets.APPSETTINGS_PATCH }}" ]; then | ||
echo "HAS_APPSETTINGS_PATCH=true" >> $GITHUB_ENV | ||
if [ -n "${{ secrets.KAMAL_DEPLOY_IP }}" ]; then | ||
echo "HAS_DEPLOY_ACTION=true" >> $GITHUB_ENV | ||
else | ||
echo "HAS_APPSETTINGS_PATCH=false" >> $GITHUB_ENV | ||
echo "HAS_DEPLOY_ACTION=false" >> $GITHUB_ENV | ||
fi | ||
# This step is for the deployment of the templates only, safe to delete | ||
- name: Modify deploy.yml | ||
if: env.HAS_DEPLOY_ACTION == 'true' | ||
run: | | ||
sed -i "s/service: my-app/service: ${{ env.repository_name_lower }}/g" config/deploy.yml | ||
sed -i "s#image: my-user/myapp#image: ${{ env.image_repository_name }}#g" config/deploy.yml | ||
sed -i "s/- 192.168.0.1/- ${{ secrets.KAMAL_DEPLOY_IP }}/g" config/deploy.yml | ||
sed -i "s/host: my-app.example.com/host: ${{ secrets.KAMAL_DEPLOY_HOST }}/g" config/deploy.yml | ||
sed -i "s/MyApp/${{ env.repository_name }}/g" config/deploy.yml | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ env.KAMAL_REGISTRY_USERNAME }} | ||
password: ${{ env.KAMAL_REGISTRY_PASSWORD }} | ||
|
||
- name: Pull latest | ||
run: docker pull ghcr.io/${{ env.image_repository_name }}:latest || true | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: '8.0' | ||
|
||
- name: Install x tool | ||
run: dotnet tool install -g x | ||
|
||
- name: Apply Production AppSettings | ||
if: env.HAS_APPSETTINGS_PATCH == 'true' | ||
working-directory: ./MyApp | ||
run: | | ||
cat <<EOF >> appsettings.json.patch | ||
${{ secrets.APPSETTINGS_PATCH }} | ||
EOF | ||
x patch appsettings.json.patch | ||
- name: Build and push Docker image | ||
run: | | ||
dotnet publish --os linux --arch x64 -c Release -p:ContainerRepository=${{ env.image_repository_name }} -p:ContainerRegistry=ghcr.io -p:ContainerImageTags=latest -p:ContainerPort=80 | ||
- name: Set up SSH key | ||
uses: webfactory/[email protected] | ||
with: | ||
|
@@ -87,7 +71,7 @@ jobs: | |
bundler-cache: true | ||
|
||
- name: Install Kamal | ||
run: gem install kamal -v 2.2.2 | ||
run: gem install kamal -v 2.3.0 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
@@ -102,18 +86,21 @@ jobs: | |
FIRST_RUN_FILE=".${{ env.repository_name }}" | ||
if ! kamal server exec --no-interactive -q "test -f $FIRST_RUN_FILE"; then | ||
kamal server exec --no-interactive -q "touch $FIRST_RUN_FILE" || true | ||
kamal deploy -q -P --version latest > /dev/null 2>&1 || true | ||
kamal deploy -q -P --version latest || true | ||
else | ||
echo "Not first run, skipping kamal app boot" | ||
fi | ||
fi | ||
- name: Ensure file permissions | ||
run: kamal server exec --no-interactive "mkdir -p /opt/docker/${{ env.repository_name }}/App_Data && chown -R 1654:1654 /opt/docker/${{ env.repository_name }}" | ||
run: | | ||
kamal server exec --no-interactive "mkdir -p /opt/docker/${{ env.repository_name }}/App_Data && chown -R 1654:1654 /opt/docker/${{ env.repository_name }}" | ||
- name: Migration | ||
if: env.HAS_MIGRATIONS == 'true' | ||
run: kamal app exec --no-reuse --no-interactive --version=latest "--AppTasks=migrate" | ||
|
||
run: | | ||
kamal server exec --no-interactive docker pull ghcr.io/${{ env.image_repository_name }}:latest || true | ||
kamal app exec --no-reuse --no-interactive --version=latest "--AppTasks=migrate" | ||
- name: Deploy with Kamal | ||
run: | | ||
kamal lock release -v | ||
|