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

Create and publish linux/amd64 and linux/arm64 builds on release #504

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 13 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ jobs:
needs: build
if: github.event_name == 'release' && github.event.action == 'created'
steps:
- name: Pushing docker images
run: sudo make push
- name: Uploading binary files
uses: actions/upload-artifact@v2
with:
name: zookeeper-exporter
path: bin/zookeeper-exporter*
- name: Check out code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Run docker login
run: |
echo "${{ secrets.DOCKER_PASS }}" | docker login -u "${{ secrets.DOCKER_USER }}" --password-stdin
- name: Build and publish docker images
run: |
make build-and-push-multiarch-image
make build-and-push-multiarch-zk-image
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG DOCKER_REGISTRY
ARG ALPINE_VERSION=3.15
FROM ${DOCKER_REGISTRY:+$DOCKER_REGISTRY/}golang:1.18-alpine${ALPINE_VERSION} as go-builder
ARG BUILDPLATFORM=linux/amd64
FROM --platform=$BUILDPLATFORM ${DOCKER_REGISTRY:+$DOCKER_REGISTRY/}golang:1.18-alpine${ALPINE_VERSION} as go-builder

ARG PROJECT_NAME=zookeeper-operator
ARG REPO_PATH=github.com/pravega/$PROJECT_NAME
Expand All @@ -9,6 +10,9 @@ ARG REPO_PATH=github.com/pravega/$PROJECT_NAME
ARG VERSION=0.0.0-localdev
ARG GIT_SHA=0000000

ARG TARGETOS=linux
ARG TARGETARCH=amd64

WORKDIR /src
COPY pkg ./pkg
COPY cmd ./cmd
Expand All @@ -25,12 +29,11 @@ COPY api/ api/
COPY controllers/ controllers/

# Build
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /src/${PROJECT_NAME} \
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -o /src/${PROJECT_NAME} \
-ldflags "-X ${REPO_PATH}/pkg/version.Version=${VERSION} -X ${REPO_PATH}/pkg/version.GitSHA=${GIT_SHA}" main.go

FROM ${DOCKER_REGISTRY:+$DOCKER_REGISTRY/}alpine:${ALPINE_VERSION} AS final


ARG PROJECT_NAME=zookeeper-operator

COPY --from=go-builder /src/${PROJECT_NAME} /usr/local/bin/${PROJECT_NAME}
Expand Down
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,28 @@ build-zk-image:
docker build --build-arg VERSION=$(VERSION) --build-arg DOCKER_REGISTRY=$(DOCKER_REGISTRY) --build-arg GIT_SHA=$(GIT_SHA) -t $(APP_REPO):$(VERSION) ./docker
docker tag $(APP_REPO):$(VERSION) $(APP_REPO):latest

build-and-push-multiarch-image:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the push target is obsolete now, should we just remove it?

docker buildx build \
--push \
--build-arg VERSION=$(VERSION) \
--build-arg DOCKER_REGISTRY=$(DOCKER_REGISTRY) \
--build-arg GIT_SHA=$(GIT_SHA) \
--platform=linux/amd64,linux/arm64 \
-t $(REPO):$(VERSION) \
-t $(REPO):latest \
.

build-and-push-multiarch-zk-image:
docker buildx build \
--push \
--build-arg VERSION=$(VERSION) \
--build-arg DOCKER_REGISTRY=$(DOCKER_REGISTRY) \
--build-arg GIT_SHA=$(GIT_SHA) \
--platform=linux/amd64,linux/arm64 \
-t $(APP_REPO):$(VERSION) \
-t $(APP_REPO):latest \
./docker

build-zk-image-swarm:
docker build --build-arg VERSION=$(VERSION)-swarm --build-arg DOCKER_REGISTRY=$(DOCKER_REGISTRY) --build-arg GIT_SHA=$(GIT_SHA) \
-f ./docker/Dockerfile-swarm -t $(APP_REPO):$(VERSION)-swarm ./docker
Expand All @@ -163,7 +185,7 @@ run-local:
go run ./main.go

login:
@docker login -u "$(DOCKER_USER)" -p "$(DOCKER_PASS)"
echo "$(DOCKER_PASS)" | docker login -u "$(DOCKER_USER)" --password-stdin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you change the login target command-line to match the test-login command-line, but then you don't use it above in the GitHub Actions workflow during the publish. Does make login not work? Do we need to bind the secrets as environment variables before calling make login?

Here is an example of binding secrets to environment variables: https://github.com/pravega/pravega/blob/master/.github/workflows/gradle.yml#L152


test-login:
echo "$(DOCKER_TEST_PASS)" | docker login -u "$(DOCKER_TEST_USER)" --password-stdin
Expand Down