## What - Fix the build number not showing up in prod correctly. - In prod I see "dev" instead of the actual number; ## Why - The build number helps to track the deployed version. ## Mood <img width="200" src="https://media4.giphy.com/media/K0KUml2ebG1vYpx11l/200w.webp?cid=36b14facis4p2almweeljo1kzjohgid2jvv66z9xtxgcwvrc&ep=v1_gifs_search&rid=200w.webp&ct=g"/> Reviewed-on: #8
111 lines
3.5 KiB
YAML
111 lines
3.5 KiB
YAML
name: Backend CD
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches: [ main ]
|
|
paths:
|
|
- 'backend/**'
|
|
- '.github/workflows/backend-cd.yml'
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: easynode-debian
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Cache npm dependencies
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.npm
|
|
key: ${{ runner.os }}-npm-${{ hashFiles('**/backend/package-lock.json') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-npm-
|
|
|
|
- name: Generate version tag
|
|
id: version
|
|
run: |
|
|
DATE=$(date +'%Y.%m.%d')
|
|
TAG="api-v${DATE}.${{ github.run_number }}"
|
|
echo "tag=${TAG}" >> $GITHUB_OUTPUT
|
|
echo "Generated tag: ${TAG}"
|
|
|
|
- name: Install dependencies
|
|
run: npm install
|
|
working-directory: ./backend
|
|
|
|
- name: Run build
|
|
run: npx tsc
|
|
working-directory: ./backend
|
|
env:
|
|
BUILD_VERSION: ${{ steps.version.outputs.tag }}
|
|
|
|
- name: Set up Docker Buildx
|
|
run: docker buildx inspect --bootstrap
|
|
|
|
- name: Log in to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Extract metadata for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: rmcampos/polpa-gestao-api
|
|
tags: |
|
|
type=raw,value=${{ steps.version.outputs.tag }}
|
|
type=raw,value=latest,enable={{ is_default_branch }}
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./backend
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=registry,ref=rmcampos/polpa-gestao-api:buildcache
|
|
cache-to: type=registry,ref=rmcampos/polpa-gestao-api:buildcache,mode=max
|
|
build-args: |
|
|
BUILD_VERSION=${{ steps.version.outputs.tag }}
|
|
|
|
- name: Build and push prisma image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: ./backend
|
|
push: true
|
|
target: prisma
|
|
tags: |
|
|
docker.io/rmcampos/polpa-gestao-api:${{ steps.version.outputs.tag }}-prisma
|
|
docker.io/rmcampos/polpa-gestao-api:latest-prisma
|
|
|
|
- name: Output Docker image URLs
|
|
run: |
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "🚀 Docker Images Published Successfully!"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo "API Image:"
|
|
echo " docker.io/rmcampos/polpa-gestao-api:${{ steps.version.outputs.tag }}"
|
|
echo " docker.io/rmcampos/polpa-gestao-api:latest"
|
|
echo ""
|
|
echo "Prisma Image:"
|
|
echo " docker.io/rmcampos/polpa-gestao-api:${{ steps.version.outputs.tag }}-prisma"
|
|
echo " docker.io/rmcampos/polpa-gestao-api:latest-prisma"
|
|
echo ""
|
|
echo "=========================================="
|
|
|
|
- name: Create and push Git tag
|
|
run: |
|
|
git config user.name "gitea-actions[bot]"
|
|
git config user.email "gitea-actions[bot]@noreply.lightroasted.vps-kinghost.net"
|
|
git tag -a ${{ steps.version.outputs.tag }} -m "Release ${{ steps.version.outputs.tag }}"
|
|
git push origin ${{ steps.version.outputs.tag }}
|
|
|