Skip to content

Build and publish Docker CI image #25

Build and publish Docker CI image

Build and publish Docker CI image #25

name: Build and publish Docker CI image
on:
push:
tags:
- "ci.v*.*.*"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-test
jobs:
build-and-push-image-amd64:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare Docker Tag
id: preparetag
run: |
TAG=$(git describe --tags)
PREFIX=$(echo "$TAG" | cut -d. -f1)
VERSION=$(echo "$TAG" | cut -d. -f2- | cut -c2-)
DOCKER_TAG="$VERSION"
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: ${{env.DOCKER_TAG}}
- name: Set short sha
shell: bash
run: |
echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
push: true
target: build_elixir
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-and-push-image-arm:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare Docker Tag
id: preparetag
run: |
TAG=$(git describe --tags)
PREFIX=$(echo "$TAG" | cut -d. -f1)
VERSION=$(echo "$TAG" | cut -d. -f2- | cut -c2-)
DOCKER_TAG="$VERSION"
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: ${{env.DOCKER_TAG}}
- name: Set short sha
shell: bash
run: |
echo "sha_short=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/arm64
push: true
target: build_elixir
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max