Release #285
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
name: Release | |
permissions: | |
packages: write | |
contents: write | |
on: | |
# Triggered on new GitHub Release | |
release: | |
types: [published] | |
# Triggered on every successful Build action | |
workflow_run: | |
workflows: ["Build"] | |
branches: [main,master] | |
types: | |
- completed | |
# Manual trigger for rollback to specific release or redeploy latest | |
workflow_dispatch: | |
inputs: | |
version: | |
default: latest | |
description: Tag you want to release. | |
required: true | |
jobs: | |
push_to_registry: | |
runs-on: ubuntu-22.04 | |
if: ${{ github.event.workflow_run.conclusion != 'failure' }} | |
steps: | |
# Checkout latest or specific tag | |
- name: checkout | |
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }} | |
uses: actions/checkout@v2 | |
- name: checkout tag | |
if: ${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }} | |
uses: actions/checkout@v2 | |
with: | |
ref: refs/tags/${{ github.event.inputs.version }} | |
- name: Setup dotnet | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: '6.0' | |
# Assign environment variables used in subsequent steps | |
- name: repository name fix | |
run: echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
# TAG_NAME defaults to 'latest' if not a release or manual deployment | |
- name: Assign version | |
run: | | |
echo "TAG_NAME=latest" >> $GITHUB_ENV | |
if [ "${{ github.event.release.tag_name }}" != "" ]; then | |
echo "TAG_NAME=${{ github.event.release.tag_name }}" >> $GITHUB_ENV | |
fi; | |
if [ "${{ github.event.inputs.version }}" != "" ]; then | |
echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV | |
fi; | |
- name: Run CI Prebuild Script | |
env: | |
deploy_api: ${{ secrets.DEPLOY_API }} | |
deploy_cdn: ${{ secrets.DEPLOY_CDN }} | |
run: | | |
if [ -e ./.deploy/ci.prebuild.sh ] | |
then | |
chmod +x ./.deploy/ci.prebuild.sh | |
./.deploy/ci.prebuild.sh | |
else | |
echo "Skipping CI prebuild" | |
fi | |
# Publish .NET Project | |
- name: Build dotnet project | |
working-directory: ./BlazorDiffusion | |
run: | | |
dotnet nuget add source "https://nuget.pkg.github.com/ServiceStack/index.json" --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github | |
dotnet publish -c Release /p:DEPLOY_API=${{ secrets.DEPLOY_API }} /p:DEPLOY_CDN=${{ secrets.DEPLOY_CDN }} /p:APP_TASKS=prerender | |
# Authenticate, build and push to GitHub Container Registry (ghcr.io) | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Build and push new docker image, skip for manual redeploy other than 'latest' | |
- name: Build and push API Docker image | |
uses: docker/build-push-action@v4 | |
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }} | |
with: | |
file: Dockerfile | |
context: . | |
push: true | |
tags: ghcr.io/${{ env.image_repository_name }}:${{ env.TAG_NAME }} | |
secrets: | | |
github_actor=${{ github.actor }} | |
github_token=${{ secrets.GITHUB_TOKEN }} | |
- name: Create env.deploy_cdn | |
run: | | |
echo "deploy_cdn=${{ secrets.DEPLOY_CDN }}" >> $GITHUB_ENV | |
# Deploy UI to R2 | |
- name: Deploy to R2 diffusion-client | |
run: | | |
aws configure set aws_access_key_id ${{ secrets.R2_ACCESS_KEY_ID }} | |
aws configure set aws_secret_access_key ${{ secrets.R2_SECRET_ACCESS_KEY }} | |
aws configure set default.region auto | |
aws configure set default.output json | |
aws s3 sync ./BlazorDiffusion/bin/Release/net6.0/publish/wwwroot s3://diffusion-client/ --endpoint-url https://b95f38ca3a6ac31ea582cd624e6eb385.r2.cloudflarestorage.com | |
deploy_via_ssh: | |
needs: push_to_registry | |
runs-on: ubuntu-22.04 | |
if: ${{ github.event.workflow_run.conclusion != 'failure' }} | |
steps: | |
# Checkout latest or specific tag | |
- name: checkout | |
if: ${{ github.event.inputs.version == '' || github.event.inputs.version == 'latest' }} | |
uses: actions/checkout@v2 | |
- name: checkout tag | |
if: ${{ github.event.inputs.version != '' && github.event.inputs.version != 'latest' }} | |
uses: actions/checkout@v2 | |
with: | |
ref: refs/tags/${{ github.event.inputs.version }} | |
# Assign environment variables used in subsequent steps | |
- name: repository name fix and env | |
run: | | |
echo "image_repository_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
echo "TAG_NAME=latest" >> $GITHUB_ENV | |
if [ "${{ github.event.release.tag_name }}" != "" ]; then | |
echo "TAG_NAME=${{ github.event.release.tag_name }}" >> $GITHUB_ENV | |
fi; | |
if [ "${{ github.event.inputs.version }}" != "" ]; then | |
echo "TAG_NAME=${{ github.event.inputs.version }}" >> $GITHUB_ENV | |
fi; | |
# Populate docker-compose.yml with variables from build process, including TAG_NAME. | |
- name: docker-compose file prep | |
uses: danielr1996/[email protected] | |
env: | |
RELEASE_VERSION: ${{ env.TAG_NAME }} | |
IMAGE_REPO: ${{ env.image_repository_name }} | |
APP_NAME: ${{ github.event.repository.name }} | |
HOST_DOMAIN: ${{ secrets.DEPLOY_API }} | |
LETSENCRYPT_EMAIL: ${{ secrets.LETSENCRYPT_EMAIL }} | |
DEPLOY_API: ${{ secrets.DEPLOY_API }} | |
DEPLOY_CDN: ${{ secrets.DEPLOY_CDN }} | |
DREAMAI_APIKEY: ${{ secrets.DREAMAI_APIKEY }} | |
SERVICESTACK_LICENSE: ${{ secrets.SERVICESTACK_LICENSE }} | |
AUTH_KEY: ${{ secrets.AUTH_KEY }} | |
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} | |
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} | |
AZURE_APP_ID: ${{ secrets.AZURE_APP_ID }} | |
AZURE_APP_SECRET: ${{ secrets.AZURE_APP_SECRET }} | |
GOOGLE_CONSUMER_KEY: ${{ secrets.GOOGLE_CONSUMER_KEY }} | |
GOOGLE_CONSUMER_SECRET: ${{ secrets.GOOGLE_CONSUMER_SECRET }} | |
FACEBOOK_APP_ID: ${{ secrets.FACEBOOK_APP_ID }} | |
FACEBOOK_APP_SECRET: ${{ secrets.FACEBOOK_APP_SECRET }} | |
with: | |
input: .deploy/docker-compose-template.yml | |
output: .deploy/${{ github.event.repository.name }}-docker-compose.yml | |
- name: Test DNS | |
run: nslookup ${{ secrets.DEPLOY_API }} | |
# Copy only the docker-compose.yml to remote server home folder | |
- name: copy compose file via scp | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.DEPLOY_API }} | |
username: ${{ secrets.DEPLOY_USERNAME }} | |
port: 22 | |
key: ${{ secrets.DEPLOY_KEY }} | |
source: ".deploy/${{ github.event.repository.name }}-docker-compose.yml" | |
target: "~/" | |
- name: daily.sh permissions | |
run: chmod +x ./.deploy/daily.sh | |
- name: copy daily.sh | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.DEPLOY_API }} | |
username: ${{ secrets.DEPLOY_USERNAME }} | |
port: 22 | |
strip_components: 1 | |
key: ${{ secrets.DEPLOY_KEY }} | |
source: ".deploy/daily.sh" | |
target: "~/" | |
# Populate litestream.yml with variables from build process, including TAG_NAME. | |
- name: litestream.yml file prep | |
uses: danielr1996/[email protected] | |
env: | |
R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} | |
R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} | |
with: | |
input: .deploy/litestream-template.yml | |
output: .deploy/litestream.yml | |
- name: copy litestream.yml file via scp | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.DEPLOY_API }} | |
username: ${{ secrets.DEPLOY_USERNAME }} | |
port: 22 | |
strip_components: 1 | |
key: ${{ secrets.DEPLOY_KEY }} | |
source: ".deploy/litestream.yml" | |
target: "/var/lib/docker/volumes/deploy_BlazorDiffusionWasm-assets/_data" | |
- name: Restore db using litestream if needed | |
uses: appleboy/[email protected] | |
env: | |
APPTOKEN: ${{ secrets.GITHUB_TOKEN }} | |
USERNAME: ${{ secrets.DEPLOY_USERNAME }} | |
with: | |
host: ${{ secrets.DEPLOY_API }} | |
username: ${{ secrets.DEPLOY_USERNAME }} | |
key: ${{ secrets.DEPLOY_KEY }} | |
port: 22 | |
envs: APPTOKEN,USERNAME | |
script: | | |
echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin | |
docker compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml pull | |
docker compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml up ${{ github.event.repository.name }}-restore --exit-code-from ${{ github.event.repository.name }}-restore | |
docker compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml up ${{ github.event.repository.name }}-restore-analytics --exit-code-from ${{ github.event.repository.name }}-restore-analytics | |
- name: Copy BlazorDiffusionWasm Seed Data to Remote Server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.DEPLOY_API }} | |
username: ${{ secrets.DEPLOY_USERNAME }} | |
port: 22 | |
key: ${{ secrets.DEPLOY_KEY }} | |
strip_components: 3 | |
source: "./BlazorDiffusion/App_Data/seed/*" | |
target: "/var/lib/docker/volumes/deploy_BlazorDiffusionWasm-mydb/_data/seed/" | |
- name: Run remote db migrations | |
uses: appleboy/[email protected] | |
env: | |
APPTOKEN: ${{ secrets.GITHUB_TOKEN }} | |
USERNAME: ${{ secrets.DEPLOY_USERNAME }} | |
with: | |
host: ${{ secrets.DEPLOY_API }} | |
username: ${{ secrets.DEPLOY_USERNAME }} | |
key: ${{ secrets.DEPLOY_KEY }} | |
port: 22 | |
envs: APPTOKEN,USERNAME | |
script: | | |
echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin | |
docker compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml pull | |
docker compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml up ${{ github.event.repository.name }}-migration --exit-code-from ${{ github.event.repository.name }}-migration | |
# Deploy Docker image with ServiceStack application using `docker compose up` remotely | |
- name: remote docker-compose up via ssh | |
uses: appleboy/[email protected] | |
env: | |
APPTOKEN: ${{ secrets.GITHUB_TOKEN }} | |
USERNAME: ${{ secrets.DEPLOY_USERNAME }} | |
with: | |
host: ${{ secrets.DEPLOY_API }} | |
username: ${{ secrets.DEPLOY_USERNAME }} | |
key: ${{ secrets.DEPLOY_KEY }} | |
port: 22 | |
envs: APPTOKEN,USERNAME | |
script: | | |
echo $APPTOKEN | docker login ghcr.io -u $USERNAME --password-stdin | |
docker compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml pull | |
docker compose -f ~/.deploy/${{ github.event.repository.name }}-docker-compose.yml up -d |