Publish Docker images #1408
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 Docker images | |
on: | |
schedule: | |
- cron: '0 10 * * *' # everyday at 10am | |
push: | |
branches: | |
- '**' | |
pull_request: | |
jobs: | |
docker: | |
runs-on: ubuntu-22.04 | |
strategy: | |
matrix: | |
image: ['', v, fpm, fpm-alpine, fpm-alpine-nginx, fpm-alpine-nginx-composer, fpm-alpine-nginx-composer-supervisor] | |
include: | |
- image: '' | |
file: Dockerfile | |
- image: fpm | |
file: fpm.Dockerfile | |
- image: v | |
file: v.Dockerfile | |
- image: fpm-alpine | |
file: fpm-alpine.Dockerfile | |
- image: fpm-alpine-nginx | |
file: fpm-alpine-nginx.Dockerfile | |
- image: fpm-alpine-nginx-composer | |
file: fpm-alpine-nginx-composer.Dockerfile | |
- image: fpm-alpine-nginx-composer-supervisor | |
file: fpm-alpine-nginx-composer-supervisor.Dockerfile | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Define tag name | |
id: tag-name | |
run: | | |
if [ "${GITHUB_REF}" == "refs/heads/master" -a "${GITHUB_EVENT_NAME}" != "pull_request" ]; then | |
curl -s https://api.github.com/repos/akaunting/akaunting/releases/latest \ | |
| jq -r .tag_name | sed \ | |
-e 's/^/::set-output name=tag::/' | |
else | |
echo -n "::set-output name=tag::" | |
echo "$GITHUB_REF" | cut -d/ -f3- | tr '/' '_' | |
fi | |
- name: Define images tags | |
id: image-tags | |
run: | | |
if [ "${GITHUB_REF}" == "refs/heads/master" -a "${GITHUB_EVENT_NAME}" != "pull_request" ]; then | |
if [ -z ${{ matrix.image }} ]; then | |
echo ${{ steps.tag-name.outputs.tag }} | sed \ | |
-e 's/\(\(\([0-9]\+\)\.[0-9]\+\)\.[0-9]\+\)/\1,\2,\3,/' \ | |
-e 's/\([^,]\+\),/akaunting\/akaunting:\1,/g' \ | |
-e 's/^/::set-output name=tags::/' \ | |
-e 's/$/akaunting\/akaunting:latest/' | |
else | |
echo ${{ steps.tag-name.outputs.tag }} | sed \ | |
-e 's/\(\(\([0-9]\+\)\.[0-9]\+\)\.[0-9]\+\)/\1-${{ matrix.image }},\2-${{ matrix.image }},\3-${{ matrix.image }},/' \ | |
-e 's/\([^,]\+\),/akaunting\/akaunting:\1,/g' \ | |
-e 's/^/::set-output name=tags::/' | |
fi | |
else | |
if [ -z ${{ matrix.image }} ]; then | |
echo -n "::set-output name=tags::akaunting/akaunting:" | |
echo "$GITHUB_REF" | cut -d/ -f3- | tr '/' '_' | |
else | |
echo -n "::set-output name=tags::akaunting/akaunting:" | |
echo "$(echo "$GITHUB_REF" | cut -d/ -f3- | tr '/' '_')-${{ matrix.image }}" | |
fi | |
fi | |
- name: Set up QEMU | |
if: matrix.image == '' || matrix.image == 'v' || matrix.image == 'fpm' || matrix.image == 'fpm-alpine' || matrix.image == 'fpm-alpine-nginx' | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
if: matrix.image == '' || matrix.image == 'v' || matrix.image == 'fpm' || matrix.image == 'fpm-alpine' || matrix.image == 'fpm-alpine-nginx' | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to DockerHub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push images | |
if: matrix.image == '' || matrix.image == 'v' || matrix.image == 'fpm' || matrix.image == 'fpm-alpine' || matrix.image == 'fpm-alpine-nginx' | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: ./${{ matrix.file }} | |
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.image-tags.outputs.tags }} | |
- name: Build and push images | |
if: matrix.image == 'fpm-alpine-nginx-composer' || matrix.image == 'fpm-alpine-nginx-composer-supervisor' | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: ./${{ matrix.file }} | |
platforms: linux/amd64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.image-tags.outputs.tags }} |