0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

ci: add staging environments (#3616)

This commit is contained in:
Gao Sun 2023-03-28 12:00:28 +08:00 committed by GitHub
parent 14143415f0
commit a33173d9c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 38 deletions

View file

@ -50,6 +50,7 @@ jobs:
run-logto:
strategy:
fail-fast: false
matrix:
target: [api, ui, ui-cloud]

View file

@ -134,10 +134,19 @@ jobs:
build-args: |
applicationinsights_connection_string=${{ (inputs.target || 'dev') == 'dev' && secrets.APPLICATIONINSIGHTS_CONNECTION_STRING || secrets.APPLICATIONINSIGHTS_CONNECTION_STRING_PROD }}
deploy-core:
deploy:
strategy:
fail-fast: false
matrix:
include:
- target: core
image: logto
- target: cloud
image: cloud
runs-on: ubuntu-latest
needs: dockerize-core
environment: ${{ inputs.target || 'dev' }}-core
needs: [dockerize-core, dockerize-cloud]
environment: ${{ inputs.target || 'dev' }}-${{ matrix.target }}-staging
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
steps:
@ -148,46 +157,17 @@ jobs:
run: echo "short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Setup Node and pnpm
if: ${{ (inputs.target || 'dev') == 'dev' }}
if: ${{ (inputs.target || 'dev') == 'dev' && matrix.target == 'core' }}
uses: silverhand-io/actions-node-pnpm-run-steps@v2
- name: Deploy database alteration
if: ${{ (inputs.target || 'dev') == 'dev' }}
if: ${{ (inputs.target || 'dev') == 'dev' && matrix.target == 'core' }}
run: |
pnpm prepack
pnpm cli db alt deploy next
env:
DB_URL: ${{ secrets.DB_URL }}
- name: Login via Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy core to containerapp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ vars.APP_NAME }}
slot-name: staging
images: ghcr.io/logto-io/logto:sha-${{ steps.sha.outputs.short }}
- name: Swap core to production
# See https://learn.microsoft.com/en-us/cli/azure/webapp/deployment/slot?view=azure-cli-latest#az-webapp-deployment-slot-swap
run: az webapp deployment slot swap -g ${{ vars.RESOURCE_GROUP }} -n ${{ vars.APP_NAME }} --slot staging
deploy-cloud:
runs-on: ubuntu-latest
needs: dockerize-cloud
environment: ${{ inputs.target || 'dev' }}-cloud
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
steps:
- uses: actions/checkout@v3
- name: Set short sha
id: sha
run: echo "short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
@ -199,15 +179,31 @@ jobs:
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy cloud to containerapp
- name: Deploy ${{ matrix.target }} to containerapp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ vars.APP_NAME }}
slot-name: staging
images: ghcr.io/logto-io/cloud:sha-${{ steps.sha.outputs.short }}
images: ghcr.io/logto-io/${{ matrix.image }}:sha-${{ steps.sha.outputs.short }}
- name: Swap cloud to production
swap-staging-prod:
strategy:
fail-fast: false
matrix:
target: [core, cloud]
runs-on: ubuntu-latest
needs: deploy
environment: ${{ inputs.target || 'dev' }}-${{ matrix.target }}
steps:
- name: Login via Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Swap ${{ matrix.target }} to production
# See https://learn.microsoft.com/en-us/cli/azure/webapp/deployment/slot?view=azure-cli-latest#az-webapp-deployment-slot-swap
run: az webapp deployment slot swap -g ${{ vars.RESOURCE_GROUP }} -n ${{ vars.APP_NAME }} --slot staging