diff --git a/.github/actions/setup-docker-environment/action.yaml b/.github/actions/setup-docker-environment/action.yaml deleted file mode 100644 index 35218844..00000000 --- a/.github/actions/setup-docker-environment/action.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: "Setup Docker" - -outputs: - sha_short: - description: "The short SHA used for image builds" - value: ${{ steps.vars.outputs.sha_short }} - tag: - description: "The tag if run against a tag, otherwise 'canary'" - value: ${{ steps.vars.outputs.tag }} - -runs: - using: "composite" - steps: - - name: Get Short SHA & Tag - id: vars - run: | - echo ::set-output name=sha_short::${GITHUB_SHA::7} - TAG=${GITHUB_REF##*/} - if [ "main" == "${TAG}" ]; then - TAG=canary - fi - echo ::set-output name=tag::${TAG:-canary} - shell: bash - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - with: - version: latest - - # - name: Login to DockerHub - # if: ${{ github.ref == 'main' && github.event.pull_request.merged == true }} - # uses: docker/login-action@v1 - # with: - # username: ${{ inputs.username }} - # password: ${{ inputs.password }} diff --git a/.github/actions/setup-image-vars/action.yaml b/.github/actions/setup-image-vars/action.yaml new file mode 100644 index 00000000..c9cdd975 --- /dev/null +++ b/.github/actions/setup-image-vars/action.yaml @@ -0,0 +1,35 @@ +name: "Setup Image Variables" + +inputs: + dockerfile: + required: true + +outputs: + tag: + description: "The tag if run against a tag, otherwise 'canary'" + value: ${{ steps.vars.outputs.tag }} + suffix: + description: "The suffix for the image package name (if any)" + value: ${{ steps.vars.outputs.suffix }} + +runs: + using: "composite" + steps: + - name: Get reference and suffix + id: vars + shell: bash + env: + DOCKERFILE: ${{ inputs.dockerfile }} + run: | + TAG=${GITHUB_REF##*/} + if [[ $GITHUB_REF == refs/heads/main ]]; then + TAG=canary + elif [[ $GITHUB_REF == refs/pull/*/merge ]]; then + TAG=pullrequest # this 'tag' is just used for caching + fi + echo ::set-output name=tag::${TAG:-canary} + SUFFIX=${DOCKERFILE##Dockerfile} + if [[ "${SUFFIX}" == "."* ]]; then + SUFFIX=${SUFFIX//./-} # convert dots into dashes + fi + echo ::set-output name=suffix::${SUFFIX} diff --git a/.github/workflows/images.yaml b/.github/workflows/images.yaml index cd8da2d1..37eb9b2e 100644 --- a/.github/workflows/images.yaml +++ b/.github/workflows/images.yaml @@ -22,18 +22,18 @@ on: - "Makefile" jobs: - build-test: - if: startsWith(github.ref, 'refs/pull/') + build: + name: Build runs-on: ubuntu-latest permissions: contents: read - name: Build + packages: write strategy: matrix: - include: - - dockerfile: Dockerfile - - dockerfile: Dockerfile.debian - - dockerfile: Dockerfile.ubuntu + dockerfile: + - Dockerfile + - Dockerfile.debian-stable-slim + - Dockerfile.ubuntu steps: - name: Checkout uses: actions/checkout@v3 @@ -43,29 +43,14 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - - name: Build - uses: docker/build-push-action@v3 with: - file: ${{ matrix.dockerfile }} - platforms: linux/amd64,linux/arm64 + version: latest - build: - if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - name: Build and Publish - env: - DOCKERHUB_USERNAME: ${{ secrets.DOCKER_USER }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Docker Environment + - name: Set up Image Variables id: vars - uses: ./.github/actions/setup-docker-environment + uses: ./.github/actions/setup-image-vars + with: + dockerfile: ${{ matrix.dockerfile }} - name: Login to GitHub Container Registry uses: docker/login-action@v1 @@ -74,24 +59,13 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and Push - uses: docker/build-push-action@v2 + - name: Build / Push + uses: docker/build-push-action@v3 with: - file: Dockerfile + file: ${{ matrix.dockerfile }} platforms: linux/amd64,linux/arm64 - push: true + push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }} tags: | - ghcr.io/${{ github.repository }}:${{ steps.vars.outputs.tag }} - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Build and Push (debian stable-slim) - uses: docker/build-push-action@v2 - with: - file: Dockerfile.debian - platforms: linux/amd64,linux/arm64 - push: true - tags: | - ghcr.io/${{ github.repository }}-debian-stable-slim:${{ steps.vars.outputs.tag }} + ghcr.io/${{ github.repository }}${{ steps.vars.outputs.suffix }}:${{ steps.vars.outputs.tag }} cache-from: type=gha cache-to: type=gha,mode=max diff --git a/Dockerfile.debian b/Dockerfile.debian-stable-slim similarity index 100% rename from Dockerfile.debian rename to Dockerfile.debian-stable-slim