Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gh-actions): Make docker and release actions work #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 78 additions & 20 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,95 @@ on:
type: string

jobs:
docker:
runs-on: ubuntu-24.04
build-with-matrix:
name: Build ${{ matrix.build.platform }}
runs-on: ubuntu-24.04${{ matrix.build.platform == 'linux/arm64/v8' && '-arm' || '' }}
strategy:
matrix:
build:
- platform: linux/amd64
arch_short: amd
- platform: linux/arm64/v8
arch_short: arm
steps:
- name: Checkout
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0

# Needed for ARM64 Docker builds
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to dockerhub
- name: Enable BuildKit
run: echo "DOCKER_BUILDKIT=1" >> $GITHUB_ENV

- name: Build and Cache Image for the ${{ matrix.build.platform }} platform
run: |
docker buildx build \
-t scylladb/hydra-loaders \
--platform ${{ matrix.build.platform }} \
--provenance false \
--metadata-file metadata \
--output push-by-digest=true,type=image,push=true \
.
echo "Metadata file info:"
cat metadata
CURRENT_SHA=$(grep -oP '"containerimage.digest": *"\Ksha256:[a-f0-9]+' metadata)
echo CURRENT_SHA=$CURRENT_SHA
echo $CURRENT_SHA > digest-${{ matrix.build.arch_short }}

- name: Upload Digest Artifact
uses: actions/upload-artifact@v4
with:
name: digest-${{ matrix.build.arch_short }}
path: digest-${{ matrix.build.arch_short }}

push-after-matrix:
name: Push multiarch images
needs: build-with-matrix
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push API
uses: docker/build-push-action@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Enable BuildKit
run: echo "DOCKER_BUILDKIT=1" >> $GITHUB_ENV

- name: Download Digests
uses: actions/download-artifact@v4
with:
file: ./Dockerfile
context: .
push: true
pull: true
platforms: "linux/amd64,linux/arm64/v8"
target: production
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
scylladb/latte:latest
scylladb/latte:${{ inputs.version }}
path: digests

- name: Create Multi-Arch Manifest and Push
run: |
ls -Rl digests
SHA_AMD=$(cat digests/digest-amd/digest-amd)
SHA_ARM=$(cat digests/digest-arm/digest-arm)
echo SHA_AMD=$SHA_AMD
echo SHA_ARM=$SHA_ARM
docker manifest create scylladb/latte:${{ inputs.version }} \
--amend scylladb/latte@$SHA_AMD \
--amend scylladb/latte@$SHA_ARM
docker manifest push scylladb/latte:${{ inputs.version }}
docker manifest inspect scylladb/latte:${{ inputs.version }}

docker manifest create scylladb/latte:latest \
--amend scylladb/latte@$SHA_AMD \
--amend scylladb/latte@$SHA_ARM
docker manifest push scylladb/latte:latest
docker manifest inspect scylladb/latte:latest
43 changes: 30 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
tags:
- '*'

jobs:
get_tag:
runs-on: ubuntu-latest
Expand All @@ -19,6 +20,26 @@ jobs:
with:
tagRegex: "(.*)"

release:
name: Create release based on tag if not exists
runs-on: ubuntu-24.04
steps:
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
run: |
set +e
if [[ "$(gh release view $tag 2>&1)" == "release not found" ]]; then
echo "Release '$tag' not found. Creating..."
gh release create "$tag" \
--repo="$GITHUB_REPOSITORY" \
--title="${GITHUB_REPOSITORY#*/} ${tag#}" \
--generate-notes
else
echo "Release '$tag' found. Skipping this step..."
fi

docker_build:
uses: ./.github/workflows/docker.yml
needs: [get_tag]
Expand All @@ -28,11 +49,11 @@ jobs:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

release:
release-artifacts:
needs: [get_tag, docker_build]
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-24.04]
os: [ubuntu-22.04, ubuntu-24.04, ubuntu-24.04-arm]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand All @@ -45,24 +66,20 @@ jobs:
command: build
args: --release

- name: Create Release
id: create_release
uses: actions/create-release@v1
- name: Get release
id: get_release
uses: bruceadams/get-release@v1.3.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.get_tag.outputs.tag }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
GITHUB_TOKEN: ${{ github.token }}

- name: Upload Release Asset
id: upload-release-asset-unix
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
# TODO: fix this URL taking, it returns 404
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ./target/release/latte
asset_name: latte-${{ matrix.os }}
asset_name: latte-${{ needs.get_tag.outputs.tag }}--${{ matrix.os }}
asset_content_type: application/octet-stream