Build & Deploy #11
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: Build & Deploy | |
on: | |
workflow_dispatch: # Allows manual triggers | |
inputs: | |
deploy_frontend: | |
description: 'Deploy the frontend' | |
required: true | |
type: boolean | |
default: true | |
deploy_backend: | |
description: 'Deploy the backend' | |
required: true | |
type: boolean | |
default: true | |
# TODO: The autodection of updated packages currently doesn't work on our portainer instance, | |
# we're just pushing all updates right now and force-updating on portainer at | |
# /#!/1/docker/stacks/releaf-canopeum?id=11®ular=true | |
# Once fixed, remove this "on push" trigger | |
# (disabled until the end of decenmber whilst Beslogic is still actively working on the project) | |
# push: | |
# branches: | |
# - main | |
# paths: | |
# - "canopeum_backend/**" | |
# - "canopeum_frontend/**" | |
# - ".github/workflows/canopeum_deploy.yml" | |
jobs: | |
GetDateTime: | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'push' || (inputs.deploy_frontend && inputs.deploy_backend) }} | |
outputs: | |
DATETIME: ${{ steps.datetime.outputs.DATETIME }} | |
steps: | |
- name: Get datetime | |
id: datetime | |
run: echo DATETIME=$(date +'%Y-%m-%d-%H-%M') >> $GITHUB_OUTPUT | |
BuildFrontend: | |
name: Build & Deploy Frontend | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'push' || inputs.deploy_frontend }} | |
needs: [GetDateTime] | |
defaults: | |
run: | |
working-directory: canopeum_frontend | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
- name: Install dependencies | |
run: npm ci | |
- name: Build project | |
run: npm run build | |
- uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish Docker image | |
id: push | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./canopeum_frontend | |
file: canopeum_frontend/Dockerfile | |
push: true | |
tags: ghcr.io/beslogic/canopeum_frontend:latest,ghcr.io/beslogic/canopeum_frontend:${{needs.GetDateTime.outputs.DATETIME}} | |
BuildBackend: | |
name: Build & Deploy Backend | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'push' || inputs.deploy_backend }} | |
needs: [GetDateTime] | |
defaults: | |
run: | |
working-directory: canopeum_backend | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get datetime | |
id: datetime | |
run: echo DATETIME=$(date +'%Y-%m-%d-%H-%M') >> $GITHUB_OUTPUT | |
- name: Publish Docker image | |
id: push | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./canopeum_backend | |
file: canopeum_backend/Dockerfile | |
push: true | |
tags: ghcr.io/beslogic/canopeum_backend:latest,ghcr.io/beslogic/canopeum_backend:${{needs.GetDateTime.outputs.DATETIME}} | |
TagRelease: | |
runs-on: ubuntu-latest | |
needs: [GetDateTime, BuildFrontend, BuildBackend] | |
# If at least one publication succeeded | |
if: always() && contains(needs.*.result, 'success') | |
steps: | |
- name: Create and push git tag | |
continue-on-error: true | |
run: | | |
git tag ${{needs.GetDateTime.outputs.DATETIME}} | |
git push origin --tags |