Publish image #151
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish image | |
on: | |
schedule: | |
- cron: '0 2 * * *' | |
workflow_dispatch: | |
push: | |
tags: | |
- v* | |
jobs: | |
build-and-push: | |
name: Build and push image | |
strategy: | |
matrix: | |
os: [self-hosted-arm64,ubuntu-latest] | |
platform: [linux/amd64, linux/arm64] | |
service_name: [frappe, mailhog, nginx] | |
exclude: | |
- os: ubuntu-latest | |
platform: linux/arm64 | |
- os: self-hosted-arm64 | |
platform: linux/amd64 | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: main | |
fetch-depth: 0 | |
- name: Set up tag | |
id: set-tag | |
run: | | |
latest_tag=$(git describe --abbrev=0 --tags) | |
if [[ "${{ github.ref == 'refs/tags/v*' }}" == 'true' ]]; then | |
latest-tag=${GITHUB_REF/refs\/tags\//} | |
fi | |
owner=$( echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]' ) | |
echo "Checkout $latest_tag" | |
git checkout "$latest_tag" | |
tag=$( cat "$GITHUB_WORKSPACE/Docker/images-tag.json" | jq -rc .${{ matrix.service_name }}) | |
echo "Image tag $tag" | |
echo "image_name=ghcr.io/${owner}/frappe-manager-${{ matrix.service_name }}:$(basename ${{ matrix.platform }})-${tag}" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
platforms: ${{ matrix.platform }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.GHCR_USER }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4 | |
with: | |
context: Docker/${{ matrix.service_name }}/. | |
push: true | |
platforms: ${{ matrix.platform }} | |
tags: ${{ env.image_name }} | |
provenance: false | |
combine: | |
name: Combine both platform images | |
needs: build-and-push | |
strategy: | |
matrix: | |
os: [ubuntu-latest] | |
service_name: [frappe, mailhog, nginx] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
ref: main | |
fetch-depth: 0 | |
- name: Set up tag | |
id: set-tag | |
run: | | |
latest_tag=$(git describe --abbrev=0 --tags) | |
if [[ "${{ github.ref == 'refs/tags/v*' }}" == 'true' ]]; then | |
latest-tag=${GITHUB_REF/refs\/tags\//} | |
fi | |
git checkout "$latest_tag" | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ secrets.GHCR_USER }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Combine manifest and push | |
run: | | |
tag=$( cat "$GITHUB_WORKSPACE/Docker/images-tag.json" | jq -rc .${{ matrix.service_name }}) | |
owner=$( echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]' ) | |
img="ghcr.io/${owner}/frappe-manager-${{ matrix.service_name }}" | |
rm -rf ~/.docker/manifests | |
docker pull "$img:amd64-${tag}" | |
docker pull "$img:arm64-${tag}" | |
docker manifest create "$img":"${tag}" \ | |
--amend "$img":amd64-${tag} \ | |
--amend "$img":arm64-${tag} | |
docker manifest push "$img:${tag}" | |
- name: Cleanup | |
run: | | |
rm -rf ~/.docker/manifests |