Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Enable multi-arch Docker images #7

Merged
merged 2 commits into from
Mar 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: |
baldissaramatheus/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 }}