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 and Push bilbomd-backend Docker Images | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- 'v*' | |
paths-ignore: | |
- '**/*.md' | |
pull_request: | |
branches: | |
- main | |
paths-ignore: | |
- '**/*.md' | |
jobs: | |
build-and-push-images: | |
if: ${{ github.actor != 'dependabot[bot]' }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Debug GitHub Event | |
run: | | |
echo "Actor: ${{ github.actor }}" | |
echo "Event Name: ${{ github.event_name }}" | |
echo "Event Payload: ${{ toJSON(github.event) }}" | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22' | |
- name: Configure npm registry | |
run: | | |
echo "@bl1231:registry=https://npm.pkg.github.com" >> .npmrc | |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc | |
- name: Install npm dependencies | |
run: npm ci | |
- name: Run npm build to test Typescript transpilation | |
run: npm run build | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
ghcr.io/${{ github.repository }}/bilbomd-backend | |
tags: | | |
type=raw,value=latest | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Generate version from tag | |
id: version | |
if: startsWith(github.ref, 'refs/tags/') | |
run: | | |
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
- name: Get version from package.json | |
id: get_version | |
run: echo "BILBOMD_BACKEND_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV | |
- name: Determine commit hash | |
run: | | |
if [ "${{ github.event_name }}" == "pull_request" ]; then | |
echo "GIT_HASH=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-7)" >> $GITHUB_ENV | |
else | |
echo "GIT_HASH=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV | |
fi | |
- name: Build and push bilbomd-backend Docker image (latest) | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: bilbomd-backend.dockerfile | |
push: true | |
platforms: linux/amd64 | |
tags: | | |
ghcr.io/${{ github.repository }}:latest | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} | |
USER_ID=${{ vars.USER_ID }} | |
GROUP_ID=${{ vars.GROUP_ID }} | |
BILBOMD_BACKEND_GIT_HASH=${{ env.GIT_HASH }} | |
BILBOMD_BACKEND_VERSION=${{ env.BILBOMD_BACKEND_VERSION }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Build and push bilbomd-backend Docker image (versioned) | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: bilbomd-backend.dockerfile | |
push: true | |
platforms: linux/amd64 | |
tags: | | |
ghcr.io/${{ github.repository }}:${{ env.BILBOMD_BACKEND_VERSION }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} | |
USER_ID=${{ vars.USER_ID }} | |
GROUP_ID=${{ vars.GROUP_ID }} | |
BILBOMD_BACKEND_GIT_HASH=${{ env.GIT_HASH }} | |
BILBOMD_BACKEND_VERSION=${{ env.BILBOMD_BACKEND_VERSION }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |