Skip to content

Commit

Permalink
feat(build): adding multi-platform support
Browse files Browse the repository at this point in the history
  • Loading branch information
jgeluk committed Aug 27, 2024
1 parent 9d88f50 commit c048dfd
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 23 deletions.
60 changes: 45 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,59 @@
name: build-image

on:
workflow_dispatch:
push:
branches: [ master ]
branches:
- 'master'
tags:
- 'v*'
pull_request:
branches:
- 'master'

permissions: read-all

jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
permissions: write-all
steps:

- name: Checkout ekgf/gloud-terraform
-
name: Checkout ekgf/gloud-terraform
uses: actions/checkout@v4

- name: set-env
-
name: set-env
run: |
echo "FQ_IMAGE_NAME=${{ vars.FQ_IMAGE_NAME }}" >> $GITHUB_ENV
echo "VERSION=$(< ./VERSION)" >> $GITHUB_ENV
- name: Build and push Docker images
uses: docker/build-push-action@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
-
name: Fetch Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.FQ_IMAGE_NAME }}
-
name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push Docker images
uses: docker/build-push-action@v6
with:
#
# TODO: Get the version number from a file (for instance localbuild.sh) or "/VERSION"
#
tags: ${{ env.FQ_IMAGE_NAME }}:latest, ${{ env.FQ_IMAGE_NAME }}:${{ env.VERSION }}
pull: true
# pull: true
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM debian:12-slim as downloader
FROM debian:12-slim AS downloader
LABEL maintainer="EKGF <[email protected]>"

ARG TERRAFORM_VERSION="1.9.5"
ARG TERRAFORM_SOPS_VERSION="1.1.1"
ARG DEBIAN_FRONTEND="noninteractive"

RUN apt-get update && apt-get install -y curl wget unzip gpg lsb-release

Expand All @@ -25,6 +26,9 @@ RUN name="terraform-provider-sops_${TERRAFORM_SOPS_VERSION}" && \
#
FROM gcr.io/cloud-builders/gcloud:latest
LABEL maintainer="EKGF <[email protected]>"
LABEL org.opencontainers.image.source="https://github.com/EKGF/gcloud-terraform"
LABEL org.opencontainers.image.description="Terraform Cloud Builder. This builder can be used to run the terraform tool in the GCE environment."
LABEL org.opencontainers.image.licenses=MIT

#
# Current user is root with home /root
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.7
0.0.8
17 changes: 11 additions & 6 deletions localbuild.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
_IMAGE_NAME="ghcr.io/ekgf/gcloud-terraform"
_IMAGE_VERSION="latest"
_MANUALLY_INCREMENTED_IMAGE_VERSION="0.0.7"
_IMAGE_NAME="$(< IMAGE_NAME)"
_IMAGE_VERSION="$(< VERSION)"

cd "${SCRIPT_DIR}" || exit 1

docker build . \
# Create a parallel multi-platform builder
docker buildx create --name mybuilder --use
# Make "buildx" the default
docker buildx install
# Build for multiple platforms
docker build \
--iidfile=.image-id \
"--tag=${_IMAGE_NAME}:${_IMAGE_VERSION}" \
"--tag=${_IMAGE_NAME}:${_MANUALLY_INCREMENTED_IMAGE_VERSION}"
--platform linux/amd64,linux/arm64 \
"--tag=${_IMAGE_NAME}:latest" \
"--tag=${_IMAGE_NAME}:${_IMAGE_VERSION}" .
exit $?

0 comments on commit c048dfd

Please sign in to comment.