Skip to content

Commit

Permalink
Updates the image building to use support multi-arch images for amd64…
Browse files Browse the repository at this point in the history
…, arm64 and armv7

Uses docker/metadata-action, docker/build-push-action and docker/login-action
  • Loading branch information
stumpylog committed Mar 12, 2023
1 parent 5654800 commit 9666a22
Showing 1 changed file with 34 additions and 55 deletions.
89 changes: 34 additions & 55 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,46 @@ jobs:
build:
name: Build

runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: FranzDiebold/github-env-vars-action@v2

- name: Set major tag name
run: echo "TAG_MAJOR=$(echo $CI_REF_NAME | cut -d. -f1)" >> $GITHUB_ENV

- name: Set major tag name
run: echo "TAG_MINOR=${{ env.TAG_MAJOR }}.$(echo $CI_REF_NAME | cut -d. -f2)" >> $GITHUB_ENV

- name: Build image
run: |
docker build --no-cache \
-t baldissaramatheus/tasks.md:latest \
-t baldissaramatheus/tasks.md:$CI_REF_NAME \
-t baldissaramatheus/tasks.md:${{ env.TAG_MAJOR }} \
-t baldissaramatheus/tasks.md:${{ env.TAG_MINOR }} \
.
- name: Save Docker image as artifact
run: |
docker save -o /tmp/image.tar \
baldissaramatheus/tasks.md:latest \
baldissaramatheus/tasks.md:$CI_REF_NAME \
baldissaramatheus/tasks.md:${{ env.TAG_MAJOR }} \
baldissaramatheus/tasks.md:${{ env.TAG_MINOR }}
- name: Upload artifact
uses: actions/upload-artifact@v2
- name: Gather Docker metadata
id: docker-meta
uses: docker/metadata-action@v4
with:
name: image
path: /tmp/image.tar

deploy:
name: Deploy

needs: [build]

runs-on: ubuntu-20.04
images: |
aldissaramatheus/tasks.md
tags: |
# Process semver like tags
# For a tag x.y.z or vX.Y.Z, output an x.y.z, x.y and x image tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Login to Docker Hub
uses: docker/login-action@v2
# Don't attempt to login is not pushing to Docker Hub
if: github.event_name != 'pull_request'
with:
username: "${{ secrets.DOCKER_USERNAME }}"
password: ${{ secrets.DOCKER_PASSWORD }}

steps:
- uses: FranzDiebold/github-env-vars-action@v2
# Login to GitHub container registry could happen here

- name: Set major tag name
run: echo "TAG_MAJOR=$(echo $CI_REF_NAME | cut -d. -f1)" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Set major tag name
run: echo "TAG_MINOR=${{ env.TAG_MAJOR }}.$(echo $CI_REF_NAME | cut -d. -f2)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Download artifact
uses: actions/download-artifact@v2
- name: Build and push
uses: docker/build-push-action@v4
with:
name: image
path: /tmp

- name: Load Docker image
run: |
docker load --input /tmp/image.tar
docker image ls -a
- name: Push Docker image
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
docker push --all-tags baldissaramatheus/tasks.md
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}

0 comments on commit 9666a22

Please sign in to comment.