Skip to content

Build Docker image

Build Docker image #61

Workflow file for this run

name: Build Docker image
on:
workflow_call:
inputs:
uploadImageAsTarball:
description: 'uploads the Docker image additionally as a tarball'
required: false
default: false
type: boolean
platforms:
description: 'platforms for docker build step'
required: false
default: ''
type: string
debug:
description: 'include debug symbols in built image'
required: false
default: false
type: boolean
pushToDockerHub:
description: 'push image to DockerHub'
required: false
default: false
type: boolean
target:
description: 'Docker image target'
required: false
default: ''
type: string
imageName:
description: 'Docker image name'
required: false
default: ''
type: string
workflow_dispatch:
inputs:
debug:
description: 'include debug symbols in built image'
required: false
default: false
type: boolean
pushToDockerHub:
description: 'push image to DockerHub'
required: false
default: false
type: boolean
target:
description: 'Docker image target'
required: false
default: ''
type: string
imageName:
description: 'Docker image name'
required: false
default: ''
type: string
env:
REPOSITORY_OWNER: ${{ github.repository_owner }}
GHCR_REGISTRY: 'ghcr.io'
GHCR_REGISTRY_USERNAME: ${{ github.actor }}
GHCR_REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
timeout-minutes: ${{ inputs.debug && 140 || 70 }}
steps:
- name: Clean up Github actions runner
uses: jlumbroso/[email protected]
with:
tool-cache: false
android: true
dotnet: true
haskell: true
large-packages: false
docker-images: true
swap-storage: false
- name: Checkout repository
uses: actions/checkout@v4
# Setup caching
- name: Set up QEMU dependency
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- name: Log into GitHub container registry
uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ env.GHCR_REGISTRY_USERNAME }}
password: ${{ env.GHCR_REGISTRY_TOKEN }}
- name: Log into DockerHub
if: ${{ inputs.pushToDockerHub }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract image name
# Set repository name as image name if inputs.imageName is empty
run: |
echo "IMAGE_NAME=${${{ inputs.imageName }}:-${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}}" >> $GITHUB_ENV
echo "IMAGE_NAME=${${{ inputs.imageName }}:-${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}}"
# - name: Extract metadata (tags, labels) for Docker image
# id: meta
# uses: docker/metadata-action@v5
# with:
# images: |
# ${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/${{ env.IMAGE_NAME }}
# ${{ inputs.pushToDockerHub && format('docker.io/{0}/{1}', env.REPOSITORY_OWNER, env.IMAGE_NAME) || '' }}
#
# flavor: |
# ${{ inputs.debug && 'prefix=debug-,onlatest=true' || '' }}
# tags: |
# type=ref,event=branch
# type=semver,pattern={{version}}
# type=semver,pattern={{major}}.{{minor}}
#
# - name: Build${{inputs.uploadImageAsTarball != true && ' and push ' || ' '}}Docker image
# id: build
# uses: docker/build-push-action@v5
# with:
# context: .
# file: "docker/Dockerfile"
# push: ${{ inputs.uploadImageAsTarball != true }}
# tags: ${{ steps.meta.outputs.tags }}
# load: ${{ inputs.uploadImageAsTarball == true }}
# labels: ${{ steps.meta.outputs.labels }}
# platforms: ${{ inputs.platforms || 'linux/arm64,linux/amd64' }}
# target: ${{ inputs.target }}
# build-args: |
# CARGO_PROFILE_RELEASE_DEBUG=${{ inputs.debug }}
# ACTIONS_CACHE_URL
# ACTIONS_RUNTIME_TOKEN
# SCCACHE_GHA_ENABLED=true
# cache-from: type=gha,scope=${{ github.workflow }}
# cache-to: type=gha,mode=max,scope=${{ github.workflow }}
#
# - name: Save docker image as tar
# if: ${{ inputs.uploadImageAsTarball }}
# run: |
# docker save -o restate.tar ${{ steps.build.outputs.imageid }}
#
# - name: Upload docker image tar as artifact
# if: ${{ inputs.uploadImageAsTarball }}
# uses: actions/upload-artifact@v4
# with:
# name: restate.tar
# path: restate.tar
# retention-days: 1
# if-no-files-found: error
#
# # Even if uploadImageAsTarball, push main images
# # This won't actually build again, it'll just use cache
# - name: Push Docker image
# if: ${{ inputs.uploadImageAsTarball && github.ref == 'refs/heads/main' }}
# uses: docker/build-push-action@v5
# with:
# context: .
# file: "docker/Dockerfile"
# push: true
# tags: ${{ steps.meta.outputs.tags }}
# load: false
# labels: ${{ steps.meta.outputs.labels }}
# target: ${{ inputs.target }}
# # ignore inputs.platforms as we always need to push both arm64 and amd64 docker images
# platforms: 'linux/arm64,linux/amd64'
# build-args: |
# CARGO_PROFILE_RELEASE_DEBUG=${{ inputs.debug }}
# ACTIONS_CACHE_URL
# ACTIONS_RUNTIME_TOKEN
# SCCACHE_GHA_ENABLED=true
# cache-from: type=gha,scope=${{ github.workflow }}
# cache-to: type=gha,mode=max,scope=${{ github.workflow }}