Skip to content

Commit

Permalink
Update GH actions to publish only to single app (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbjoralt authored Oct 17, 2023
1 parent 6511984 commit 53a8ab4
Showing 1 changed file with 46 additions and 73 deletions.
119 changes: 46 additions & 73 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,80 +9,7 @@ on:
workflow_dispatch:

jobs:
build-and-deploy-frontend:
name: 'Build and deploy Frontend'
runs-on: ubuntu-latest
environment: Production

defaults:
run:
working-directory: frontend

steps:
- name: 'Checkout'
uses: actions/checkout@v3

- name: 'Setup Node.js version'
uses: actions/setup-node@v3
with:
node-version: "18.x"

- name: 'Restore cache'
uses: actions/cache@v3
with:
path: |
frontend/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-

- name: 'Install ci dependencies'
run: yarn --frozen-lockfile --ignore-scripts

- name: Build with Next.js (NO)
run: |
yarn build
mv ./build/static ./build/standalone/build
cp -r ./public ./build/standalone/
mv ./build ./build-no
env:
NEXT_PUBLIC_VIBES_BACKEND_URL: ${{ vars.NEXT_PUBLIC_VIBES_BACKEND_URL_NO }}
NEXT_PUBLIC_CLIENT_ID: ${{ vars.NEXT_PUBLIC_CLIENT_ID }}
NEXT_PUBLIC_TENANT_ID: ${{ vars.NEXT_PUBLIC_TENANT_ID }}
NEXT_PUBLIC_APP_SCOPE: ${{ vars.NEXT_PUBLIC_APP_SCOPE }}

- name: Build with Next.js (SE)
run: |
yarn build
mv ./build/static ./build/standalone/build
cp -r ./public ./build/standalone
mv ./build ./build-se
env:
NEXT_PUBLIC_VIBES_BACKEND_URL: ${{ vars.NEXT_PUBLIC_VIBES_BACKEND_URL_SE }}
NEXT_PUBLIC_CLIENT_ID: ${{ vars.NEXT_PUBLIC_CLIENT_ID }}
NEXT_PUBLIC_TENANT_ID: ${{ vars.NEXT_PUBLIC_TENANT_ID }}
NEXT_PUBLIC_APP_SCOPE: ${{ vars.NEXT_PUBLIC_APP_SCOPE }}


- name: Deploy to App Service (NO)
id: deploy-to-webapp-no
uses: azure/webapps-deploy@v2
with:
app-name: 'vibes-frontend-norway-prod'
slot-name: 'Production'
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_FRONTEND_NO }}
package: ./frontend/build-no/standalone

- name: Deploy to App Service (SE)
id: deploy-to-webapp-se
uses: azure/webapps-deploy@v2
with:
app-name: 'vibes-frontend-sweden-prod'
slot-name: 'Production'
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_FRONTEND_SE }}
package: ./frontend/build-se/standalone

build-and-deploy-backend:
name: 'Build and deploy Backend'
Expand Down Expand Up @@ -123,3 +50,49 @@ jobs:
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_BACKEND_SE }} # Define secret variable in repository settings as per action documentation
package: 'backend/Api/build'

build-frontend:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

- name: Log in to GitHub container registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Lowercase the repo name and username
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}

- name: Build and push container image to registry
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
push: true
tags: ghcr.io/${{ env.REPO }}-frontend:${{ github.sha }}
file: Frontend.Dockerfile

deploy-frontend:
permissions:
contents: none
runs-on: ubuntu-latest
needs: build-frontend
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Lowercase the repo name and username
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: vibes-frontend-prod
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_FRONTEND }}
images: 'ghcr.io/${{ env.REPO }}-frontend:${{ github.sha }}'

0 comments on commit 53a8ab4

Please sign in to comment.