Skip to content

Build Docker Image

Build Docker Image #26

name: Build Docker Image
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to build from'
required: true
type: choice
default: 'master'
options:
- 'master'
- 'development'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Load Buildx
run: docker buildx create --name mybuilder --use
if: runner.os == 'Linux'
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Log into registry ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version from package.json
if: ${{ github.event.inputs.branch == 'master' }}
run: echo "DOCKER_TAG=$(jq -r '.version' package.json)" >> $GITHUB_ENV
- name: Extract Docker metadata (master)
if: ${{ github.event.inputs.branch == 'master' }}
id: meta_m
uses: docker/metadata-action@v5
with:
tags: |
type=raw,value=latest
type=raw,value=${{ env.DOCKER_TAG }}
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
- name: Extract Docker metadata (development)
if: ${{ github.event.inputs.branch == 'development' }}
id: meta_d
uses: docker/metadata-action@v5
with:
tags: |
type=raw,value=development
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
- name: Build and push production Docker image (master)
if: ${{ github.event.inputs.branch == 'master' }}
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ steps.meta_m.outputs.tags }}
labels: ${{ steps.meta_m.outputs.labels }}
- name: Build and push production Docker image (development)
if: ${{ github.event.inputs.branch == 'development' }}
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ steps.meta_d.outputs.tags }}
labels: ${{ steps.meta_d.outputs.labels }}