Skip to content

Commit

Permalink
Add support to multi architecture docker image using a github action
Browse files Browse the repository at this point in the history
  • Loading branch information
shahidhs-ibm committed Jan 12, 2023
1 parent c5e40da commit b37103e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/docker-builds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and publish cfssl docker image

on:
push:
tags:
- 'v*.*.*'

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get tag
id: cfssl
run: echo "::set-output name=tag::$(git describe --tags HEAD)"

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Docker hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64,linux/s390x
push: true
tags: cfssl:${{ steps.cfssl.outputs.tag }}
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM golang:1.16.15@sha256:35fa3cfd4ec01a520f6986535d8f70a5eeef2d40fb8019ff626da24989bdd4f1
FROM --platform=${BUILDPLATFORM} golang:1.19.3@sha256:d388153691a825844ebb3586dd04d1c60a2215522cc445701424205dffc8a83e

ARG TARGETOS TARGETARCH

WORKDIR /workdir
COPY . /workdir

RUN git clone https://github.com/cloudflare/cfssl_trust.git /etc/cfssl && \
make clean && \
make all && cp bin/* /usr/bin/
GOOS=${TARGETOS} GOARCH=${TARGETARCH} make all && cp bin/* /usr/bin/

EXPOSE 8888

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ all: bin/cfssl bin/cfssl-bundle bin/cfssl-certinfo bin/cfssl-newkey bin/cfssl-sc

bin/%: $(shell find . -type f -name '*.go')
@mkdir -p $(dir $@)
go build -ldflags $(LDFLAGS) -o $@ ./cmd/$(@F)
GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -ldflags $(LDFLAGS) -o $@ ./cmd/$(@F)

.PHONY: install
install: install-cfssl install-cfssl-bundle install-cfssl-certinfo install-cfssl-newkey install-cfssl-scan install-cfssljson install-mkbundle install-multirootca
Expand All @@ -25,7 +25,7 @@ serve:

bin/goose: $(shell find vendor -type f -name '*.go')
@mkdir -p $(dir $@)
go build -o $@ ./vendor/bitbucket.org/liamstask/goose/cmd/goose
GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -o $@ ./vendor/bitbucket.org/liamstask/goose/cmd/goose

.PHONY: clean
clean:
Expand Down

0 comments on commit b37103e

Please sign in to comment.