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

Add github-action and Dockerfile for multi-arch build #207

Merged
merged 2 commits into from
Aug 19, 2021
Merged
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
53 changes: 53 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build piraeus-operator
on:
workflow_dispatch:
push:
tags:
- v*
branches:
- master
pull_request:
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: linux/amd64,linux/arm64

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

- name: login to registry
if: ${{ github.event_name != 'pull_request' }}
env:
QUAYIO_USERNAME: ${{ secrets.DOCKER_USERNAME }}
QUAYIO_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
docker login --username=${QUAYIO_USERNAME} --password-stdin quay.io <<< "${QUAYIO_PASSWORD}"

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
quay.io/piraeusdatastore/piraeus-operator
tags: |
type=sha
type=raw,value=latest
type=ref,event=tag
type=ref,event=pr
- name: Build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
file: ./build/Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
41 changes: 0 additions & 41 deletions .github/workflows/check-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,44 +81,3 @@ jobs:
# Checks
- name: Run pre-commit checks on changes files
uses: pre-commit/action@v2.0.0

build:
name: build
runs-on: ubuntu-20.04
needs:
- checks
- golangci
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
# use operator-sdk
- uses: actions/cache@v1
id: operator-sdk-cache
with:
path: ~/operator-sdk/bin
key: ${{ runner.os }}-operator-sdk-${{ env.OPERATOR_SDK_VERSION }}
- name: setup operator-sdk
run: ./.github/workflows/scripts/install-operator-sdk.sh ${OPERATOR_SDK_VERSION}
# use go module sources
- uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-build-
- name: Build with operator-sdk
run: operator-sdk build quay.io/piraeusdatastore/piraeus-operator:latest
- name: Push docker image
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: quay.io
repository: piraeusdatastore/piraeus-operator
dockerfile: ./build/Dockerfile
# master -> latest
# tag -> tag
# pull request -> pr-{pull request}
tag_with_ref: true
add_git_labels: true
push: ${{ github.event_name != 'pull_request' }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Temporary Build Files
build/_output
build/_test
# Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
### Emacs ###
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ all: update upload

.PHONY: update
update:
$(OPERATORSDKCMD) build --image-build-args "--no-cache=$(NOCACHE)" $(PROJECT):$(TAG)
Copy link
Member

Choose a reason for hiding this comment

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

Don't delete the whole makefile. Just replace this line with docker build -t $(PROJECT):$(TAG) --no-cache=$(NOCACHE) -f build/Dockerfile.multiarch .

Copy link
Member

Choose a reason for hiding this comment

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

Needs to changed to -f build/Dockerfile now

docker build -t $(PROJECT):$(TAG) --no-cache=$(NOCACHE) -f build/Dockerfile .
docker tag $(PROJECT):$(TAG) $(PROJECT):latest


.PHONY: upload
upload:
for r in $(REGISTRY); do \
Expand Down
20 changes: 8 additions & 12 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
FROM debian:buster
FROM golang:buster AS builder

ENV OPERATOR=/usr/local/bin/piraeus-operator \
USER_UID=1001 \
USER_NAME=piraeus-operator
COPY . /build
WORKDIR /build
RUN CGO_ENABLED=0 go build -o ./_output/bin/piraeus-operator --ldflags '-extldflags "-static"' -gcflags all=-trimpath=. --asmflags all=-trimpath=. github.com/piraeusdatastore/piraeus-operator/cmd/manager

FROM gcr.io/distroless/static:latest
# install operator binary
COPY build/_output/bin/piraeus-operator ${OPERATOR}

COPY build/bin /usr/local/bin
RUN /usr/local/bin/user_setup

ENTRYPOINT ["/usr/local/bin/entrypoint"]

USER ${USER_UID}
COPY --from=builder /build/_output/bin/piraeus-operator /usr/local/bin/piraeus-operator
USER 1001
ENTRYPOINT ["/usr/local/bin/piraeus-operator"]