Skip to content

Commit

Permalink
feat: publish multiple arch images (#232)
Browse files Browse the repository at this point in the history
* feat: publish multiple arch images

* test ci in pr

* setup buildx

* multi arch dockerfile

* fix

* test build

* test build

* add label

* add label

* add label
  • Loading branch information
keidarcy committed May 22, 2024
1 parent e0d1ec4 commit 6ea15a7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ name: publish docker image
on:
push:
branches: ['master']
pull_request:

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
Expand All @@ -22,13 +23,28 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
with:
image: tonistiigi/binfmt:latest
platforms: arm64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3
# https://github.com/docker/build-push-action/issues/761#issuecomment-1575006515
with:
driver-opts: |
image=moby/buildkit:v0.12.5
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
Expand All @@ -39,6 +55,7 @@ jobs:
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=sha,format=long
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
Expand All @@ -48,5 +65,8 @@ jobs:
with:
context: .
push: true
platforms: linux/arm64,linux/amd64
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Easily Manage AWS ECS Resources in Terminal
35 changes: 31 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
# Build e1s in go image
FROM golang:1.22.2-alpine as builder

# Set build argument for target architecture
ARG TARGETARCH

WORKDIR /src/e1s
COPY . ./
RUN go mod vendor && \
go build -o e1s ./cmd/e1s

# Set the GOARCH environment variable based on the TARGETARCH
RUN GOARCH="" && \
if [ "$TARGETARCH" = "amd64" ]; then \
GOARCH="amd64"; \
elif [ "$TARGETARCH" = "arm64" ]; then \
GOARCH="arm64"; \
else \
echo "Unsupported architecture: $TARGETARCH"; \
exit 1; \
fi && \
GOARCH=$GOARCH go mod vendor && \
GOARCH=$GOARCH go build -o e1s ./cmd/e1s


# Install the session manager plugin in ubuntu image
# https://github.com/aws/session-manager-plugin/issues/12
FROM ubuntu:20.04 as sessionmanagerplugin

ADD https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb .
RUN dpkg -i "session-manager-plugin.deb"
ARG TARGETARCH

# Install dependencies for dpkg and download tools
RUN apt-get update && apt-get install -y curl dpkg && rm -rf /var/lib/apt/lists/*

# Use the build argument to determine the correct package URL and installation method
RUN if [ "$TARGETARCH" = "amd64" ]; then \
curl -o session-manager-plugin.deb https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb; \
elif [ "$TARGETARCH" = "arm64" ]; then \
curl -o session-manager-plugin.deb https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_arm64/session-manager-plugin.deb; \
else \
echo "Unsupported architecture: $TARGETARCH"; \
exit 1; \
fi && \
dpkg -i session-manager-plugin.deb && rm session-manager-plugin.deb

FROM alpine
COPY --from=builder /src/e1s/e1s /e1s
Expand Down

0 comments on commit 6ea15a7

Please sign in to comment.