From 1531e1e5686f8f80f52f4de173f4361fcad41436 Mon Sep 17 00:00:00 2001 From: Matej Velikonja Date: Thu, 19 Jan 2023 12:57:26 +0100 Subject: [PATCH] feat(gh-actions): add docker build --- .github/workflows/docker.yml | 31 +++++++++++++++++++++++++++++++ Dockerfile | 6 ++---- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..0971c3f --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,31 @@ +name: Build and Push Docker Image + +on: + workflow_run: + workflows: [Tests] + types: + - completed + +jobs: + build-and-push: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + file: ./Dockerfile + push: false + tags: kiwicom/k8s-vault-operator:latest diff --git a/Dockerfile b/Dockerfile index 8f9cca1..ced75ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,16 +12,14 @@ COPY go.sum go.sum RUN go mod download # Copy the go source -COPY main.go main.go -COPY api/ api/ -COPY controllers/ controllers/ +COPY . . # Build # the GOARCH has not a default value to allow the binary be built according to the host where the command # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager ./cmd/manager/main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details