105 lines
3.4 KiB
YAML
105 lines
3.4 KiB
YAML
name: buildx
|
|
|
|
on:
|
|
push:
|
|
pull_request:
|
|
|
|
jobs:
|
|
buildx:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
# Step 1: Checkout the code
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
# Step 2: Prepare variables for building and tagging the image
|
|
- name: Prepare
|
|
id: prepare
|
|
run: |
|
|
GHCR_IMAGE=ghcr.io/${GITHUB_REPOSITORY}
|
|
DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x
|
|
|
|
VERSION=$(echo ${GITHUB_REF#refs/*/} | sed 's/\//-/g') # Replace / with - in tag name
|
|
TAGS="${GITHUB_REPOSITORY}:${VERSION}"
|
|
|
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
TAGS="$TAGS,${GITHUB_REPOSITORY}:latest"
|
|
elif [[ $VERSION == "master" ]]; then
|
|
TAGS="$TAGS,${GITHUB_REPOSITORY}:beta"
|
|
fi
|
|
|
|
GHCR_TAGS="${GHCR_IMAGE}:${VERSION}"
|
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
GHCR_TAGS="$GHCR_TAGS,${GHCR_IMAGE}:latest"
|
|
elif [[ $VERSION == "master" ]]; then
|
|
GHCR_TAGS="$GHCR_TAGS,${GHCR_IMAGE}:beta"
|
|
fi
|
|
|
|
echo "platforms=${DOCKER_PLATFORMS}" >> $GITHUB_OUTPUT
|
|
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
|
|
echo "ghcr-tags=${GHCR_TAGS}" >> $GITHUB_OUTPUT
|
|
|
|
# Step 3: Set up QEMU for multi-platform builds
|
|
- name: Set up QEMU
|
|
id: qemu
|
|
uses: docker/setup-qemu-action@v3
|
|
with:
|
|
image: tonistiigi/binfmt:latest
|
|
platforms: all
|
|
|
|
# Step 4: Set up Docker Buildx
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
id: buildx
|
|
|
|
# Step 5: Login to DockerHub
|
|
- name: Login to DockerHub
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
# Step 5.5: Login to GitHub Container Registry
|
|
- name: Login to GHCR
|
|
if: github.event_name != 'pull_request'
|
|
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
|
|
|
# Step 6: Debug Build
|
|
- name: Debug Build on PR
|
|
run: |
|
|
docker buildx build --load .
|
|
|
|
# Step 7: Test the built image
|
|
- name: Test
|
|
run: |
|
|
docker compose version
|
|
docker compose --file docker-compose.test.yml up --exit-code-from sut --timeout 10 --build
|
|
|
|
# Step 8: Build and Push (if not a PR)
|
|
- name: Build and push
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.prepare.outputs.tags }}
|
|
platforms: ${{ steps.prepare.outputs.platforms }}
|
|
|
|
# Step 9: Push to GitHub Container Registry
|
|
- name: Push to GHCR
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: ${{ steps.prepare.outputs.ghcr-tags }}
|
|
platforms: ${{ steps.prepare.outputs.platforms }}
|
|
|
|
# Step 10: Update Docker Hub Description
|
|
- name: Docker Hub Description
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
uses: peter-evans/dockerhub-description@v4
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
|
short-description: ${{ github.event.repository.description }}
|