Skip to content

Commit

Permalink
fix dev build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Nov 30, 2023
1 parent 994f81d commit 3ceba80
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 33 deletions.
73 changes: 48 additions & 25 deletions .github/workflows/_shared-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: Reusable build workflow
on:
workflow_call:
inputs:
ref:
description: 'The branch, tag or SHA to build'
required: true
type: string
release:
description: 'Release version tag for this build'
default: ''
Expand All @@ -13,13 +17,13 @@ on:
default: false
required: true
type: boolean
repository:
docker_repository:
description: 'Docker Hub Repository'
default: ''
required: false
type: string
tag:
description: 'Docker Image Tag'
docker_tag_prefix:
description: 'Docker Image Tag Prefix'
default: ''
required: false
type: string
Expand All @@ -43,6 +47,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

# setup global dependencies
- name: Set up go
Expand Down Expand Up @@ -74,6 +80,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

# setup global dependencies
- name: Set up go
Expand Down Expand Up @@ -110,6 +118,8 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

# setup global dependencies
- name: Set up go
Expand Down Expand Up @@ -141,6 +151,8 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

# setup global dependencies
- name: Set up go
Expand Down Expand Up @@ -172,6 +184,8 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

# setup global dependencies
- name: Set up go
Expand Down Expand Up @@ -205,6 +219,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}

- name: Get build version
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -235,13 +252,13 @@ jobs:
- name: Build amd64 docker image
run: |
docker build . --file Dockerfile-stub \
--tag ${{ inputs.repository }}:${{ inputs.tag }}-amd64 \
--tag ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }}-amd64 \
--tag ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-amd64 \
--tag ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-amd64 \
--platform=linux/amd64
- name: Push amd64 docker images
run: |
docker push ${{ inputs.repository }}:${{ inputs.tag }}-amd64
docker push ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }}-amd64
docker push ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-amd64
docker push ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-amd64
build_arm64_docker_image:
name: Build arm64 docker image
Expand All @@ -250,6 +267,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: Get build version
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -282,13 +301,13 @@ jobs:
- name: Build arm64 docker image
run: |
docker build . --file Dockerfile-stub \
--tag ${{ inputs.repository }}:${{ inputs.tag }}-arm64 \
--tag ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }}-arm64 \
--tag ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-arm64 \
--tag ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-arm64 \
--platform=linux/arm64
- name: Push arm64 docker image
run: |
docker push ${{ inputs.repository }}:${{ inputs.tag }}-arm64
docker push ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }}-arm64
docker push ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-arm64
docker push ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-arm64
build_multiarch_image:
name: Build multiarch docker image
Expand All @@ -297,6 +316,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: Get build version
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Expand All @@ -313,12 +334,12 @@ jobs:
# build multiarch image
- name: Build multiarch docker manifest
run: |
docker manifest create ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }} \
--amend ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }}-amd64 \
--amend ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }}-arm64
docker manifest create ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }} \
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-amd64 \
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-arm64
- name: Push multiarch docker manifest
run: |
docker manifest push ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }}
docker manifest push ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}
build_extra_image:
name: Build additional docker manifests
Expand All @@ -330,6 +351,8 @@ jobs:
tag: ${{ fromJSON(inputs.additional_tags) }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: Get build version
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Expand All @@ -346,18 +369,18 @@ jobs:
# build multiarch image
- name: "Build additional docker manifest: ${{ matrix.tag }}"
run: |
docker manifest create ${{ inputs.repository }}:${{ matrix.tag }}-amd64 \
--amend ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }}-amd64
docker manifest create ${{ inputs.docker_repository }}:${{ matrix.tag }}-amd64 \
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-amd64
docker manifest create ${{ inputs.repository }}:${{ matrix.tag }}-arm64 \
--amend ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }}-arm64
docker manifest create ${{ inputs.docker_repository }}:${{ matrix.tag }}-arm64 \
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-arm64
docker manifest create ${{ inputs.repository }}:${{ matrix.tag }} \
--amend ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }}-amd64 \
--amend ${{ inputs.repository }}:${{ inputs.tag }}-${{ steps.vars.outputs.sha_short }}-arm64
docker manifest create ${{ inputs.docker_repository }}:${{ matrix.tag }} \
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-amd64 \
--amend ${{ inputs.docker_repository }}:${{ inputs.docker_tag_prefix }}-${{ steps.vars.outputs.sha_short }}-arm64
- name: "Push additional docker manifest: ${{ matrix.tag }}"
run: |
docker manifest push ${{ inputs.repository }}:${{ matrix.tag }}-amd64
docker manifest push ${{ inputs.repository }}:${{ matrix.tag }}-arm64
docker manifest push ${{ inputs.repository }}:${{ matrix.tag }}
docker manifest push ${{ inputs.docker_repository }}:${{ matrix.tag }}-amd64
docker manifest push ${{ inputs.docker_repository }}:${{ matrix.tag }}-arm64
docker manifest push ${{ inputs.docker_repository }}:${{ matrix.tag }}
30 changes: 26 additions & 4 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name: Build DEV version

on:
pull_request:
branches: [ "master" ]
pull_request_target:
types: [synchronize]
workflow_dispatch:
inputs:
docker_tag:
Expand All @@ -15,24 +15,44 @@ jobs:
name: "Get PR info"
runs-on: ubuntu-latest
outputs:
run_builds: ${{ steps.loadinfo.outputs.run_builds }}
commit_ref: ${{ steps.loadinfo.outputs.commit_ref }}
build_docker: ${{ steps.loadinfo.outputs.build_docker }}
docker_tag: ${{ steps.loadinfo.outputs.docker_tag }}
steps:
- name: "Load PR info"
id: loadinfo
run: |
run_builds="true"
has_docker_image_label="${{ contains(github.event.pull_request.labels.*.name, 'build-docker-image') }}"
echo "docker image label: $has_docker_image_label"
branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
echo "branch name: $branch_name"
commit_repo="$GITHUB_REPOSITORY"
commit_ref="${{ github.event.pull_request.head.sha }}"
if [[ -z "$commit_ref" ]]; then
commit_ref="${{ github.sha }}"
fi
echo "repository: $commit_repo"
echo "commit: $commit_ref"
manual_tag="${{ inputs.docker_tag }}"
if [[ ! -z "$manual_tag" ]]; then
has_docker_image_label="true"
branch_name="$manual_tag"
fi
if [[ "$branch_name" == "master" ]] || [[ "$branch_name" =~ ^v[0-9] ]]; then
echo "Invalid branch name! Skipping builds"
run_builds="false"
fi
echo "run_builds=$run_builds" >> $GITHUB_OUTPUT
echo "commit_ref=$commit_ref" >> $GITHUB_OUTPUT
echo "build_docker=$has_docker_image_label" >> $GITHUB_OUTPUT
echo "docker_tag=$branch_name" >> $GITHUB_OUTPUT
Expand All @@ -43,11 +63,13 @@ jobs:
build_binaries:
name: "Build Dora"
needs: [prinfo, check_source]
if: ${{ needs.prinfo.outputs.run_builds == 'true' }}
uses: ./.github/workflows/_shared-build.yaml
with:
ref: ${{ needs.prinfo.outputs.commit_ref }}
docker: ${{ needs.prinfo.outputs.build_docker == 'true' }}
repository: "ethpandaops/dora"
tag: ${{needs.prinfo.outputs.docker_tag}}
docker_repository: "ethpandaops/dora"
docker_tag_prefix: ${{needs.prinfo.outputs.docker_tag}}
additional_tags: "['${{needs.prinfo.outputs.docker_tag}}','${{needs.prinfo.outputs.docker_tag}}-latest']"
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/build-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ jobs:
needs: [check_source]
uses: ./.github/workflows/_shared-build.yaml
with:
ref: ${{ github.sha }}
release: "snapshot"
docker: true
repository: "ethpandaops/dora"
tag: "master"
docker_repository: "ethpandaops/dora"
docker_tag_prefix: "master"
additional_tags: "['master','master-latest']"
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ jobs:
name: "Build Dora"
uses: ./.github/workflows/_shared-build.yaml
with:
ref: ${{ github.sha }}
release: "v${{ inputs.version }}"
docker: true
repository: "ethpandaops/dora"
tag: "v${{ inputs.version }}"
docker_repository: "ethpandaops/dora"
docker_tag_prefix: "v${{ inputs.version }}"
additional_tags: "['v${{ inputs.version }}','latest']"
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
Expand Down

0 comments on commit 3ceba80

Please sign in to comment.