From b89c0ea2792ade91841cec408ca51c90ec0b41e6 Mon Sep 17 00:00:00 2001 From: Mark Metcalfe Date: Thu, 21 Nov 2024 08:40:29 +1300 Subject: [PATCH] Build images using github actions --- .github/workflows/build-image.yml | 57 ++++++++++++++++++++++++ .github/workflows/release.yml | 72 +++++++++++++++++++++++++++++++ README.md | 2 +- 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build-image.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 00000000..90f0c055 --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,57 @@ +on: + workflow_call: + inputs: + image: + required: true + type: string + context: + required: true + type: string + dockerfile: + required: false + type: string + default: 'Dockerfile' + multiarch: + required: false + type: boolean + default: true + +jobs: + build-image: + name: Build ${{ inputs.image }} image + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 1 + - name: Log in to Docker Hub + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1 + with: + images: totara/docker-dev-${{ inputs.image }} + # Adds tags for 'x.x.x' release version and 'multiarch' if multiarch + tags: | + type=semver,pattern={{version}} + ${{ inputs.multiarch == true && 'type=raw,multiarch' || '' }} + - name: Set up QEMU (to support building for both amd64 and arm64) + if: ${{ inputs.multiarch == true }} + uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 + with: + platforms: ${{ inputs.multiarch == true && 'linux/amd64,linux/arm64' || 'linux/amd64' }} + - name: Build and push images + uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0 + with: + context: ${{ inputs.context }} + file: ${{ inputs.context }}/${{ inputs.dockerfile }} + push: true + platforms: ${{ inputs.multiarch == true && 'linux/amd64,linux/arm64' || 'linux/amd64' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..1445e091 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,72 @@ +name: Build docker-dev images upon a new release + +on: + release: + types: + - created + +jobs: + build-apache-image: + name: Build Apache image + uses: ./.github/workflows/build-image.yml + with: + image: apache + context: ./apache + secrets: inherit + + build-nginx-image: + name: Build Nginx image + uses: ./.github/workflows/build-image.yml + with: + image: nginx + context: ./nginx + secrets: inherit + + build-mssql-images: + name: Build MSSQL images + strategy: + matrix: + version: [2017, 2019, 2022] + uses: ./.github/workflows/build-image.yml + with: + image: mssql${{ matrix.version }} + context: ./mssql + dockerfile: ${{ matrix.version }}/Dockerfile + multiarch: false # Mssql does not support multiple architectures + secrets: inherit + + build-php-images: + name: Build PHP base images + strategy: + matrix: + version: [53, 54, 55, 56, 70, 71, 72, 73, 80, 81, 82, 83] + uses: ./.github/workflows/build-image.yml + with: + image: php${{ matrix.version }} + context: ./php/php${{ matrix.version }} + secrets: inherit + + build-php-debug-images: + name: Build PHP debug images + needs: build-php-images + strategy: + matrix: + version: [53, 54, 55, 56, 70, 71, 72, 73, 80, 81, 82, 83] + uses: ./.github/workflows/build-image.yml + with: + image: php${{ matrix.version }}-debug + context: ./php/php${{ matrix.version }}-debug + secrets: inherit + + build-php-cron-images: + name: Build PHP cron images + needs: build-php-images + strategy: + matrix: + # Note: no cron container for v5.3 + version: [54, 55, 56, 70, 71, 72, 73, 80, 81, 82, 83] + uses: ./.github/workflows/build-image.yml + with: + image: php${{ matrix.version }}-cron + context: ./php/php${{ matrix.version }}-cron + secrets: inherit diff --git a/README.md b/README.md index db8e35e9..f3e13295 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Release](https://img.shields.io/github/v/release/totara/totara-docker-dev)](../../releases) [![Release Date](https://img.shields.io/github/release-date/totara/totara-docker-dev)](../../releases) -[![Build Status](https://travis-ci.com/totara/totara-docker-dev.svg?branch=master)](https://travis-ci.com/totara/totara-docker-dev) +[![Build Status](https://img.shields.io/github/actions/workflow/status/totara/totara-docker-dev/release.yml)](../../actions/workflows/release.yml) [![Issues](https://img.shields.io/github/issues/totara/totara-docker-dev)](../../issues) [![License](https://img.shields.io/github/license/totara/totara-docker-dev)](../../LICENCE)