Skip to content

Commit

Permalink
build(docker): push to async production build (#1423)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced Docker image handling process for improved organization and
management.
- **Bug Fixes**
- Simplified and corrected the digest handling process for better
clarity and accuracy.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
antoinezanardi authored Nov 13, 2024
1 parent 8183c7d commit e10510d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
53 changes: 35 additions & 18 deletions .github/workflows/deploy-to-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,52 @@ jobs:
- name: Set up Docker Buildx 🏗️
uses: docker/setup-buildx-action@v3

- name: Docker meta 📦
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: ${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }}

- name: Build and push Docker image 🐳
uses: docker/build-push-action@v6
id: build
with:
context: .
file: ./Dockerfile
push: true
platforms: ${{ matrix.platform }}
tags: ${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,push=true
labels: ${{ steps.meta.outputs.labels }}

- name: Set formatted platform directory in environment variable 🌿
run: echo "PLATFORM_DIR=$(echo "${{ matrix.platform }}" | sed 's/\//-/g')" >> "$GITHUB_ENV"

- name: Export digest 📦
run: |
mkdir -p /tmp/digests
echo "${{ matrix.platform }}=${{ steps.build.outputs.digest }}" > "/tmp/digests/${{ matrix.tag }}-${{ matrix.platform }}-digest.txt"
mkdir -p /tmp/digests/${{ matrix.tag }}/${{ env.PLATFORM_DIR }}
echo "${{ steps.build.outputs.digest }}" > "/tmp/digests/${{ matrix.tag }}/${{ env.PLATFORM_DIR }}-digest.txt"
- name: Upload digest 📦
uses: actions/upload-artifact@v4
with:
name: digests-${{ matrix.tag }}
path: /tmp/digests/${{ matrix.tag }}-${{ matrix.platform }}-digest.txt
name: docker-digest-${{ matrix.tag }}-${{ env.PLATFORM_DIR }}
path: /tmp/digests/${{ matrix.tag }}/${{ env.PLATFORM_DIR }}-digest.txt

merge-images-into-manifest-list:
name: Merge images into a manifest list 🗂️
runs-on: ubuntu-latest
strategy:
matrix:
tag:
- ${{ github.event.release.tag_name }}
- latest
needs: upload-to-docker-hub
steps:
- name: Download digests 📩
uses: actions/download-artifact@v4
with:
name: digests
path: /tmp/digests
name: docker-digest-${{ matrix.tag }}-*
path: /tmp/digests/${{ matrix.tag }}
merge-multiple: true

- name: Set up Docker Buildx 🏗️
Expand All @@ -80,26 +95,28 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: ${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }}

- name: Log in to Docker Hub 🔐
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}

- name: Create and push manifest list 📦
- name: Create manifest list and push 📦
run: |
for tag in "${{ github.event.release.tag_name }}" "latest"; do
docker buildx imagetools create --tag "${{ env.REGISTRY_IMAGE }}:$tag" \
"$(cat "/tmp/digests/${tag}-linux/amd64-digest.txt")" \
"$(cat "/tmp/digests/${tag}-linux/arm64-digest.txt")"
DIGESTS=""
for f in /tmp/digests/${{ matrix.tag }}/*-digest.txt; do
PLATFORM=$(basename "$f" | sed 's/-digest.txt//')
DIGEST=$(cat "$f")
DIGESTS+="${{ env.REGISTRY_IMAGE }}:${PLATFORM}@${DIGEST} "
done
docker buildx imagetools create --tag "${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }}" "$DIGESTS"
- name: Inspect manifest lists 🕵️
run: |
for tag in "${{ github.event.release.tag_name }}" "latest"; do
docker buildx imagetools inspect "${{ env.REGISTRY_IMAGE }}:$tag"
done
- name: Inspect manifest list 🕵️
run: docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }}

deploy-to-production:
name: Deploy to production server 🚀
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/push-on-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,15 @@ jobs:

- name: Create manifest list and push 📦
run: |
ls -la /tmp/digests
# Initialize DIGESTS variable
DIGESTS=""
for f in /tmp/digests/*-digest.txt; do
PLATFORM=$(basename "$f" | sed 's/-digest.txt//; s/\//-/g')
PLATFORM=$(basename "$f" | sed 's/-digest.txt//')
DIGEST=$(cat "$f")
DIGESTS+="${{ env.REGISTRY_IMAGE }}:${PLATFORM}@${DIGEST} "
done
docker buildx imagetools create --tag "${{ env.REGISTRY_IMAGE }}:develop" $DIGESTS
docker buildx imagetools create --tag "${{ env.REGISTRY_IMAGE }}:develop" "$DIGESTS"

- name: Inspect manifest list 🕵️
run: |
Expand Down

0 comments on commit e10510d

Please sign in to comment.