Skip to content

Commit

Permalink
Merge pull request #731 from kristof-mattei/update-from-upstream
Browse files Browse the repository at this point in the history
update from upstream
  • Loading branch information
kristof-mattei authored Apr 3, 2024
2 parents 57cb540 + 6ea6013 commit 08e7cae
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 95 deletions.
136 changes: 105 additions & 31 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ env:
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
# just a name, but storing it separately as we're nice people
DOCKER_IMAGE_ARTIFACT_NAME: Docker image
DOCKER_IMAGE_OUTPUT_LOCATION: /tmp
DOCKER_IMAGE_TAR_LOCATION: /tmp/docker-image.tar # notice /tmp same as DOCKER_IMAGE_OUTPUT_LOCATION
RUSTFLAGS: --deny=warnings

concurrency:
Expand All @@ -45,8 +42,8 @@ jobs:

steps:
- name: Repo has docker container?
id: determine
shell: bash
id: determine
run: |
HAS_CONTAINER="${{ vars.HAS_CONTAINER }}"
echo "has_container=${HAS_CONTAINER:-false}" >> ${GITHUB_OUTPUT}
Expand Down Expand Up @@ -107,8 +104,10 @@ jobs:
- name: Set up toolchain
shell: bash
run: |
rm ${HOME}/.cargo/bin/rustfmt
rm ${HOME}/.cargo/bin/cargo-fmt
rm ${HOME}/.cargo/bin/rust-analyzer
rm ${HOME}/.cargo/bin/rustfmt
rustup update
cargo --version
Expand All @@ -132,8 +131,8 @@ jobs:
cargo binstall --no-confirm cocogitto --target x86_64-unknown-linux-musl --pkg-url "{ repo }/releases/download/{ version }/{ name }-{ version }-{ target }.tar.gz" --bin-dir "{ bin }" --pkg-fmt tgz
- name: Calculate next version
id: version
shell: bash
id: version
run: |
VERSION="$(cog bump --auto --dry-run || true)"
Expand Down Expand Up @@ -184,8 +183,10 @@ jobs:
- name: Set up toolchain
shell: bash
run: |
rm ${HOME}/.cargo/bin/rustfmt
rm ${HOME}/.cargo/bin/cargo-fmt
rm ${HOME}/.cargo/bin/rust-analyzer
rm ${HOME}/.cargo/bin/rustfmt
rustup update
cargo --version
Expand Down Expand Up @@ -228,8 +229,10 @@ jobs:
- name: Set up toolchain
shell: bash
run: |
rm ${HOME}/.cargo/bin/rustfmt
rm ${HOME}/.cargo/bin/cargo-fmt
rm ${HOME}/.cargo/bin/rust-analyzer
rm ${HOME}/.cargo/bin/rustfmt
rustup update
cargo --version
Expand Down Expand Up @@ -270,8 +273,10 @@ jobs:
- name: Set up toolchain
shell: bash
run: |
rm ${HOME}/.cargo/bin/rustfmt
rm ${HOME}/.cargo/bin/cargo-fmt
rm ${HOME}/.cargo/bin/rust-analyzer
rm ${HOME}/.cargo/bin/rustfmt
rustup update
cargo --version
Expand Down Expand Up @@ -387,8 +392,10 @@ jobs:
- name: Set up toolchain
shell: bash
run: |
rm ${HOME}/.cargo/bin/rustfmt
rm ${HOME}/.cargo/bin/cargo-fmt
rm ${HOME}/.cargo/bin/rust-analyzer
rm ${HOME}/.cargo/bin/rustfmt
rustup update
cargo --version
Expand All @@ -399,40 +406,68 @@ jobs:
args: --workspace --all-targets --all-features --no-deps

docker-build:
name: Build Docker container
name: Build Docker container for ${{ matrix.platform.docker }}-${{ matrix.platform.rust }}
runs-on: ubuntu-latest
needs:
- calculate-version
# if: ... is not needed because calculate-version will not run if we disable building the docker container
env:
APPLICATION_NAME: PLACEHOLDER # overridden in step 'Set application name', this is merely to satisfy the linter
PATH_TO_TAR: PALCEHOLDER # same ^
PLATFORM_PAIR: PLACEHOLDER # same ^
PLATFORM_UNIQUE_TAG: PLACEHOLDER # same ^
strategy:
fail-fast: false
matrix:
platform:
- docker: linux/amd64
rust: x86_64-unknown-linux-musl
- docker: linux/arm64
rust: aarch64-unknown-linux-musl
steps:
- name: Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
with:
show-progress: false

- name: Prepare name
run: |
platform=${{ matrix.platform.docker }}-${{ matrix.platform.rust }}
echo "PLATFORM_PAIR=${platform//\//-}" >> ${GITHUB_ENV}
- name: Set the Cargo.toml version before we copy in the data into the Docker container
shell: bash
run: |
./.github/scripts/update-version.sh ${{ needs.calculate-version.outputs.version }}
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0

# TODO validate no changes between github.event.pull_request.head.sha and the actual current sha (representing the hypothetical merge)

- name: Lowercase the image name
shell: bash
run: |
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${GITHUB_ENV}
- name: Set Docker tag
shell: bash
run: |
PLATFORM_UNIQUE_TAG=pr-${{ github.event.pull_request.base.sha }}-${{ github.event.pull_request.head.sha }}-${{ env.PLATFORM_PAIR }}
echo "PLATFORM_UNIQUE_TAG=${PLATFORM_UNIQUE_TAG##*/}" >> ${GITHUB_ENV}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
id: meta
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=pr,suffix=-latest
type=raw,value=pr-${{ github.event.pull_request.base.sha }}-${{ github.event.pull_request.head.sha }}
type=raw,value=${{ env.PLATFORM_UNIQUE_TAG }}
labels: |
org.opencontainers.image.version=pr-${{ github.event.number }}
org.opencontainers.image.source=${{ github.event.pull_request.html_url }}
Expand All @@ -444,11 +479,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Lowercase the image name
shell: bash
run: |
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${GITHUB_ENV}
- name: Set application name
shell: bash
run: |
Expand All @@ -457,23 +487,28 @@ jobs:
- name: Build Docker image
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
id: build
with:
build-args: |
APPLICATION_NAME=${{ env.APPLICATION_NAME }}
TARGET=${{ matrix.platform.rust }}
context: .
# this container is THE PR's artifact, and we will re-tag it
# once the PR has been accepted
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
outputs: type=docker,dest=${{ env.DOCKER_IMAGE_TAR_LOCATION }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ env.PLATFORM_PAIR }}
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ env.PLATFORM_PAIR }},mode=max
platforms: ${{ matrix.platform.docker }}
outputs: type=docker,dest=/tmp/${{ env.PLATFORM_UNIQUE_TAG }}.tar

- name: Upload artifact
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: ${{ env.DOCKER_IMAGE_ARTIFACT_NAME }}
path: ${{ env.DOCKER_IMAGE_TAR_LOCATION }}
name: containers-${{ env.PLATFORM_PAIR }}
path: /tmp/${{ env.PLATFORM_UNIQUE_TAG }}.tar
if-no-files-found: error
retention-days: 1

docker-publish:
name: Publish Docker container
Expand All @@ -493,8 +528,9 @@ jobs:
- name: Download artifact
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
with:
name: ${{ env.DOCKER_IMAGE_ARTIFACT_NAME }}
path: ${{ env.DOCKER_IMAGE_OUTPUT_LOCATION }}
path: /tmp/containers
pattern: containers-*
merge-multiple: true

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
Expand All @@ -503,15 +539,53 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Load image from artifact
- name: Lowercase the image name
shell: bash
run: |
docker load --input ${{ env.DOCKER_IMAGE_TAR_LOCATION }}
echo "IMAGE_NAME=${IMAGE_NAME,,}" >> ${GITHUB_ENV}
- name: Push image with all tags
- name: Load images from artifacts
shell: bash
run: |
docker push ${REGISTRY,,}/${IMAGE_NAME,,} --all-tags
ls -l /tmp/containers/
for container in /tmp/containers/*
do
echo $container
docker load --input $container
tag=$(basename -- $container .tar)
echo ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:${tag}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${tag}
done
- name: Extract Docker metadata
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
id: meta
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=pr,suffix=-latest
type=raw,value=pr-${{ github.event.pull_request.base.sha }}-${{ github.event.pull_request.head.sha }}
- name: Merge images
shell: bash
working-directory: /tmp/containers
run: |
# all files in dir
platform_tags=(*)
# yeet extension
platform_tags=${platform_tags[@]%.tar}
new_tags="${{ join(steps.meta.outputs.tags, ' ') }}"
new_tags=$(printf -- '--tag %s ' $new_tags)
expanded_platform_tags=$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:%s ' $platform_tags)
docker buildx imagetools create $new_tags $expanded_platform_tags
for new_tag in $(echo "${{ join(steps.meta.outputs.tags, ' ') }}"); do
docker buildx imagetools inspect --raw $new_tag
done
all-done:
name: All done
Expand Down
Loading

0 comments on commit 08e7cae

Please sign in to comment.