Skip to content

Commit

Permalink
fixup! Update docker.yml workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tillrohrmann committed Jul 26, 2024
1 parent 1185d57 commit 0e01094
Showing 1 changed file with 94 additions and 138 deletions.
232 changes: 94 additions & 138 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ on:
required: false
default: false
type: boolean
buildCli:
description: 'build cli Docker image'
target:
description: 'Docker image target'
required: false
default: false
type: boolean
default: ''
type: string
imageName:
description: 'Docker image name'
required: false
default: ''
type: string

workflow_dispatch:
inputs:
Expand All @@ -41,6 +46,16 @@ on:
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 }}
Expand Down Expand Up @@ -93,138 +108,79 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract image name
# Set repository name as image name
# Set repository name as image name if inputs.imageName is empty
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for server Docker image
id: meta-server
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: Extract metadata (tags, labels) for cli Docker image
id: meta-cli
if: ${{ inputs.buildCli }}
uses: docker/metadata-action@v5
with:
images: |
${{ format('{0}/{1}/{2}-cli', env.GHCR_REGISTRY, env.REPOSITORY_OWNER, env.IMAGE_NAME) }}
${{ inputs.pushToDockerHub && format('docker.io/{0}/{1}-cli', 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 ' || ' '}}server Docker image
id: build-server
uses: docker/build-push-action@v5
with:
context: .
file: "docker/Dockerfile"
push: ${{ inputs.uploadImageAsTarball != true }}
tags: ${{ steps.meta-server.outputs.tags }}
load: ${{ inputs.uploadImageAsTarball == true }}
labels: ${{ steps.meta-server.outputs.labels }}
platforms: ${{ inputs.platforms || 'linux/arm64,linux/amd64' }}
target: "server"
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: Build${{inputs.uploadImageAsTarball != true && ' and push ' || ' '}}cli Docker image
id: build-cli
if: ${{ inputs.buildCli }}
uses: docker/build-push-action@v5
with:
context: .
file: "docker/Dockerfile"
push: ${{ inputs.uploadImageAsTarball != true }}
tags: ${{ steps.meta-cli.outputs.tags }}
load: ${{ inputs.uploadImageAsTarball == true }}
labels: ${{ steps.meta-cli.outputs.labels }}
platforms: ${{ inputs.platforms || 'linux/arm64,linux/amd64' }}
target: "cli"
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-server.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 server 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-server.outputs.tags }}
load: false
labels: ${{ steps.meta-server.outputs.labels }}
target: "server"
# 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 }}

# Even if uploadImageAsTarball, push main images
# This won't actually build again, it'll just use cache
- name: Push cli Docker image
if: ${{ inputs.buildCli && inputs.uploadImageAsTarball && github.ref == 'refs/heads/main' }}
uses: docker/build-push-action@v5
with:
context: .
file: "docker/Dockerfile"
push: true
tags: ${{ steps.meta-cli.outputs.tags }}
load: false
labels: ${{ steps.meta-cli.outputs.labels }}
target: "cli"
# 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 }}
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 }}

0 comments on commit 0e01094

Please sign in to comment.