diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index 93d4e22a..955a70fa 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -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' @@ -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 }}' \ No newline at end of file