[Workflow: Build] Configure staging build on pushes to main

This commit is contained in:
arttu
2024-08-03 14:16:28 +03:00
parent f8a5fcc3c0
commit cd3aff0e45
+12 -4
View File
@@ -1,9 +1,17 @@
name: Publish production containers
name: Build and deploy containers
# Pushes to main will build containers with staging env's and push them as staging images, whereas release goes to production.
on:
release:
push:
branches:
- main
env:
BACKEND_IMAGE_NAME: nowdb-backend
FRONTEND_IMAGE_NAME: nowdb-frontend
BACKEND_IMAGE_NAME: ${{ github.event.label.name == 'release' && 'nowdb-backend' || 'nowdb-backend-staging' }}
FRONTEND_IMAGE_NAME: ${{ github.event.label.name == 'release' && 'nowdb-frontend' || 'nowdb-frontend-staging' }}
BACKEND_URL: ${{ github.event.label.name == 'release' && secrets.BACKEND_URL_PROD || secrets.BACKEND_URL_STAGING }}
RUNNING_ENV: ${{ github.event.label.name == 'release' && 'prod' || 'staging' }}
ENABLE_WRITE: ${{ github.event.label.name == 'release' && 'false' || 'true' }}
# Backend env's are defined inside the cluster, whereas frontend's have to be defined at build stage, that's why they're here
jobs:
push_backend:
@@ -47,7 +55,7 @@ jobs:
- uses: actions/checkout@v4
- name: Build image
run: docker build frontend --tag $FRONTEND_IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" --build-arg BACKEND_URL=${{ vars.BACKEND_URL }} --build-arg RUNNING_ENV=prod
run: docker build frontend --tag $FRONTEND_IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" --build-arg BACKEND_URL=${BACKEND_URL} --build-arg RUNNING_ENV=${RUNNING_ENV} --build-arg ENABLE_WRITE=${ENABLE_WRITE}
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin