Skip to content

Publish Docker Image #14

Publish Docker Image

Publish Docker Image #14

name: Publish Docker Image
description: Publish Docker image for a new version.
on:
workflow_call:
inputs:
version:
description: 'Release version Format: x.y.z-[alpha|beta|pre].n'
required: true
type: string
pre_release:
description: 'Is this a pre-release?'
required: false
default: "false"
type: string
workflow_dispatch:
inputs:
version:
description: 'Release version Format: x.y.z-[alpha|beta|pre].n'
required: true
type: string
pre_release:
description: 'Is this a pre-release?'
required: false
default: false
type: boolean
env:
REGISTRY: ghcr.io
jobs:
test:
uses: ./.github/workflows/test.yml
publish:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Environment
uses: ./.github/workflows/setup
- name: Setup ENV Variables
run: |
echo "IMAGE_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "FULL_IMAGE_NAME=${{ env.REGISTRY }}/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.FULL_IMAGE_NAME }}
- name: Build Binary
run: bun compile linux-x64-baseline ${{ inputs.version }} --no-version-tag
- name: Set Tags
id: set-tags
run: |
echo "tags=${{ env.FULL_IMAGE_NAME }}:${{ inputs.version }}" >> $GITHUB_ENV
if [[ "${{ inputs.pre_release }}" != "true" ]]; then
echo "tags+=,${{ env.FULL_IMAGE_NAME }}:latest" >> $GITHUB_ENV
fi
echo "${{ env.tags }}"
- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/Dockerfile
push: true
tags: ${{ env.tags }}
labels: |
org.opencontainers.image.title=${{ steps.meta.outputs.title }}
org.opencontainers.image.description=${{ steps.meta.outputs.description }}
org.opencontainers.image.version=${{ inputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ steps.meta.outputs.created }}
org.opencontainers.image.authors=${{ steps.meta.outputs.authors }}
org.opencontainers.image.url=${{ steps.meta.outputs.url }}