Skip to content

Commit

Permalink
feat(ci): tomorrow
Browse files Browse the repository at this point in the history
  • Loading branch information
Savid committed Apr 8, 2024
1 parent 2263bd0 commit 9bb3812
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 124 deletions.
240 changes: 116 additions & 124 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -1,127 +1,119 @@
name: Build
description: Build and push a docker image to Docker Hub

on:
workflow_call:
inputs:
source_repository:
description: The source repository to build from
type: string
required: true
source_ref:
description: The branch, tag or SHA to checkout and build from
type: string
required: true
build_script:
description: The bash script path in this repository to run instead of the Docker build & push script. You must push the image yourself.
type: string
required: false
target_tag:
description: Docker hub tag to push to
type: string
required: true
target_repository:
description: Docker hub repository to push to
type: string
required: true
target_dockerfile:
description: Dockerfile path in this repository to build from. Omit to use source repository Dockerfile
type: string
default: ./source/Dockerfile
required: false
platform:
description: The platform to build for
type: string
required: true
runner:
description: The runner to use
type: string
required: true
secrets:
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true
MACOS_PASSWORD:
required: true

jobs:
build:
name: Build
runs-on: ${{ inputs.runner }}
steps:
- name: get git commit hash
id: git_commit_hash
shell: bash
run: |
cd source
echo "git_commit_hash=$(echo $(git log --pretty=format:'%h' -n 1))" >> $GITHUB_OUTPUT
- name: Set up Docker Context for Buildx
shell: bash
id: buildx-context
run: |
docker context use builders || docker context create builders
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
endpoint: builders
- name: Unlock MacOS keychain for Docker Hub login
shell: bash
if: runner.os == 'macOS'
run: |
security -v unlock-keychain -p ${{ secrets.MACOS_PASSWORD }} ~/Library/Keychains/login.keychain-db
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# run the build script if it exists instead of the docker build & push
- name: Build script
shell: bash
if: inputs.build_script
env:
source_repository: ${{ inputs.source_repository }}
source_ref: ${{ inputs.source_ref }}
target_tag: ${{ inputs.target_tag }}
target_repository: ${{ inputs.target_repository }}
target_dockerfile: ${{ inputs.target_dockerfile || './source/Dockerfile' }}
source_git_commit_hash: ${{ steps.git_commit_hash.outputs.git_commit_hash }}
run: |
${{ inputs.build_script }}
- name: Image digest & tags (build script)
shell: bash
if: inputs.build_script
run: |
cat << EOF
digest: $(docker image inspect --format='{{index .RepoDigests 0}}' ${{ inputs.target_repository }}:${{ inputs.target_tag }} | grep -oE "@(.*)" | cut -d'@' -f2-)
tags:
${{ inputs.target_repository }}:${{ inputs.target_tag }}
${{ inputs.target_repository }}:${{ inputs.target_tag }}-${{ steps.git_commit_hash.outputs.git_commit_hash }}
EOF
# only run the docker build & push if a build script wasn't specified
- name: Docker build & push
if: ${{ inputs.build_script == '' }}
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./source
file: ${{ inputs.target_dockerfile }}
# two tags;
# - $target_tag
# - $target_tag-commit
tags: ${{ inputs.target_repository }}:${{ inputs.target_tag }}-${{ steps.git_commit_hash.outputs.git_commit_hash }},${{ inputs.target_repository }}:${{ inputs.target_tag }}
push: true
platforms: ${{ inputs.platform }}
labels: |
ethpandaops.io.repo=${{ inputs.source_repository }}
ethpandaops.io.commitRef=${{ inputs.source_ref }}
- name: Image digest & tags
shell: bash
if: ${{ inputs.build_script == '' }}
run: |
cat << EOF
digest: ${{ steps.docker_build.outputs.digest }}
tags:
${{ inputs.target_repository }}:${{ inputs.target_tag }}
${{ inputs.target_repository }}:${{ inputs.target_tag }}-${{ steps.git_commit_hash.outputs.git_commit_hash }}
EOF
inputs:
source_repository:
description: The source repository to build from
type: string
required: true
source_ref:
description: The branch, tag or SHA to checkout and build from
type: string
required: true
build_script:
description: The bash script path in this repository to run instead of the Docker build & push script. You must push the image yourself.
type: string
required: false
target_tag:
description: Docker hub tag to push to
type: string
required: true
target_repository:
description: Docker hub repository to push to
type: string
required: true
target_dockerfile:
description: Dockerfile path in this repository to build from. Omit to use source repository Dockerfile
type: string
default: ./source/Dockerfile
required: false
platform:
description: The platform to build for
type: string
required: true
# Secrets
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true
MACOS_PASSWORD:
required: true

runs:
using: composite
steps:
- name: get git commit hash
id: git_commit_hash
shell: bash
run: |
cd source
echo "git_commit_hash=$(echo $(git log --pretty=format:'%h' -n 1))" >> $GITHUB_OUTPUT
- name: Set up Docker Context for Buildx
shell: bash
id: buildx-context
run: |
docker context use builders || docker context create builders
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
endpoint: builders
- name: Unlock MacOS keychain for Docker Hub login
shell: bash
if: runner.os == 'macOS'
run: |
security -v unlock-keychain -p ${{ inputs.MACOS_PASSWORD }} ~/Library/Keychains/login.keychain-db
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ inputs.DOCKER_USERNAME }}
password: ${{ inputs.DOCKER_PASSWORD }}
# run the build script if it exists instead of the docker build & push
- name: Build script
shell: bash
if: inputs.build_script
env:
source_repository: ${{ inputs.source_repository }}
source_ref: ${{ inputs.source_ref }}
target_tag: ${{ inputs.target_tag }}
target_repository: ${{ inputs.target_repository }}
target_dockerfile: ${{ inputs.target_dockerfile || './source/Dockerfile' }}
source_git_commit_hash: ${{ steps.git_commit_hash.outputs.git_commit_hash }}
run: |
${{ inputs.build_script }}
- name: Image digest & tags (build script)
shell: bash
if: inputs.build_script
run: |
cat << EOF
digest: $(docker image inspect --format='{{index .RepoDigests 0}}' ${{ inputs.target_repository }}:${{ inputs.target_tag }} | grep -oE "@(.*)" | cut -d'@' -f2-)
tags:
${{ inputs.target_repository }}:${{ inputs.target_tag }}
${{ inputs.target_repository }}:${{ inputs.target_tag }}-${{ steps.git_commit_hash.outputs.git_commit_hash }}
EOF
# only run the docker build & push if a build script wasn't specified
- name: Docker build & push
if: ${{ inputs.build_script == '' }}
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./source
file: ${{ inputs.target_dockerfile }}
# two tags;
# - $target_tag
# - $target_tag-commit
tags: ${{ inputs.target_repository }}:${{ inputs.target_tag }}-${{ steps.git_commit_hash.outputs.git_commit_hash }},${{ inputs.target_repository }}:${{ inputs.target_tag }}
push: true
platforms: ${{ inputs.platform }}
labels: |
ethpandaops.io.repo=${{ inputs.source_repository }}
ethpandaops.io.commitRef=${{ inputs.source_ref }}
- name: Image digest & tags
shell: bash
if: ${{ inputs.build_script == '' }}
run: |
cat << EOF
digest: ${{ steps.docker_build.outputs.digest }}
tags:
${{ inputs.target_repository }}:${{ inputs.target_tag }}
${{ inputs.target_repository }}:${{ inputs.target_tag }}-${{ steps.git_commit_hash.outputs.git_commit_hash }}
EOF
3 changes: 3 additions & 0 deletions .github/actions/deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ jobs:
target_dockerfile: ${{ inputs.target_dockerfile }}
platform: ${{ matrix.config.platform }}
runner: ${{ matrix.config.runner }}
DOCKER_USERNAME: "${{ vars.DOCKER_USERNAME }}"
DOCKER_PASSWORD: "${{ secrets.DOCKER_PASSWORD }}"
MACOS_PASSWORD: "${{ secrets.MACOS_PASSWORD }}"

0 comments on commit 9bb3812

Please sign in to comment.