Skip to content

Commit

Permalink
Create go-filetree-test.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
carry0987 committed Nov 12, 2024
1 parent f61df51 commit 25b4626
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions .github/workflows/ghcr/go-filetree-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: FileTree-API Docker Build and Push

on:
push:
tags:
- 'go-filetree-test-*'

jobs:
build-and-push:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform: linux/amd64
- os: buildjet-2vcpu-ubuntu-2204-arm
platform: linux/arm64
outputs:
version: ${{ env.version }}
latest: ${{ env.IS_LATEST }}
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Check out Sharp-API repo
uses: actions/checkout@v4
with:
repository: 'carry0987/FileTree-API'
token: ${{ secrets.GH_CLONE_TOKEN }}
path: 'Go/FileTree-API/source'

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

- name: Login to DockerHub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Prepare the Docker tags list
id: prep
run: |
FULL_VERSION=$(echo ${{ github.ref }} | sed -e 's,.*/go-filetree-test-,,')
VERSION=${FULL_VERSION%-latest}
TAGS="ghcr.io/${{ github.actor }}/filetree-api:${VERSION}"
IS_LATEST=false
if [[ ${{ matrix.platform }} == "linux/amd64" ]]; then
SUFFIX="-amd64"
elif [[ ${{ matrix.platform }} == "linux/arm64" ]]; then
SUFFIX="-arm64"
fi
TAGS="ghcr.io/${{ github.actor }}/filetree-api:${VERSION}${SUFFIX}"
if [[ "$FULL_VERSION" == *"-latest" ]]; then
TAGS="$TAGS,ghcr.io/${{ github.actor }}/filetree-api:latest${SUFFIX}"
IS_LATEST=true
fi
echo "TAGS=$TAGS" >> $GITHUB_ENV
echo "PROGRAM_VERSION=${VERSION%}" >> $GITHUB_ENV
echo "version=${VERSION%}" >> $GITHUB_ENV
echo "IS_LATEST=$IS_LATEST" >> $GITHUB_ENV
echo "PROGRAM_VERSION=${VERSION%}"
echo "Building with tags: $TAGS"
- name: Start multi-arch build and push
uses: docker/build-push-action@v6
with:
context: Go/FileTree-API
file: Go/FileTree-API/Dockerfile
build-args: PROGRAM_VERSION=${{ env.PROGRAM_VERSION }}
push: true
tags: ${{ env.TAGS }}
platforms: ${{ matrix.platform }}
provenance: false

- name: Logout from GHCR
run: docker logout ghcr.io

manifest:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Login to DockerHub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set image prefix
run: echo "IMAGE_PREFIX=ghcr.io/${{ github.actor }}/filetree-api:${{ needs.build-and-push.outputs.version }}" >> $GITHUB_ENV

- name: Create and push manifest images
uses: Noelware/docker-manifest-action@master
with:
inputs: ghcr.io/${{ github.actor }}/filetree-api:${{ needs.build-and-push.outputs.version }}
images: ${{ env.IMAGE_PREFIX }}-amd64,${{ env.IMAGE_PREFIX }}-arm64
push: true
amend: true

- name: Check outputs for latest
run: echo "Latest ${{ needs.build-and-push.outputs.latest }}"

- name: Set image prefix for latest
if: ${{ needs.build-and-push.outputs.latest == 'true' }}
run: echo "IMAGE_PREFIX=ghcr.io/${{ github.actor }}/filetree-api:latest" >> $GITHUB_ENV

- name: Create and push manifest images for latest
if: ${{ needs.build-and-push.outputs.latest == 'true' }}
uses: Noelware/docker-manifest-action@master
with:
inputs: ${{ env.IMAGE_PREFIX }}
images: ${{ env.IMAGE_PREFIX }}-amd64,${{ env.IMAGE_PREFIX }}-arm64
push: true
amend: true

- name: Logout from GHCR
run: docker logout ghcr.io

0 comments on commit 25b4626

Please sign in to comment.