diff --git a/.github/workflows/docker-image-pre-release.yaml b/.github/workflows/docker-image-pre-release.yaml new file mode 100644 index 0000000..216c041 --- /dev/null +++ b/.github/workflows/docker-image-pre-release.yaml @@ -0,0 +1,61 @@ +name: Pre-build Docker Image + +on: + push: + branches: + - 'release/v*' + +permissions: + # Allow creating GitHub release + contents: write + +env: + DOCKER_HUB_REPO: arybolovlev/docker-operator + RELEASE_NOTES: /tmp/release-notes.txt + +jobs: + pre-release-docker-image: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Go + id: golang + uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Docker image metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.DOCKER_HUB_REPO }} + tags: | + type=semver,pattern={{version}} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + # Due to the Docker Buildx limitation only one platrom can be here. + platforms: amd64 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + build-contexts: | + golang=docker-image://golang:${{ steps.golang.outputs.go-version }} + # Due to the Docker Buildx limitation only one platrom can be here. + platforms: linux/amd64 + push: false + load: true + tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/docker-image-release.yaml b/.github/workflows/docker-image-release.yaml index bc41f8c..0c46db1 100644 --- a/.github/workflows/docker-image-release.yaml +++ b/.github/workflows/docker-image-release.yaml @@ -2,8 +2,8 @@ name: Build and Publish Docker Image on: push: - branches: - - 'release/v*' + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' permissions: # Allow creating GitHub release diff --git a/CHANGELOG.md b/CHANGELOG.md index 0be7dce..a706119 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,3 @@ -## 0.0.8 (December 6, 2022) +## 0.0.1 (April 13, 2023) -🐛 BUG FIXES: - -* Fix more issues. - -## 0.0.7 (November 25, 2022) - -🐛 BUG FIXES: - -* Fix more issues. - -## 0.0.6 (November 22, 2022) - -* Fix concurrency issue. +* Fix a bug. diff --git a/Dockerfile b/Dockerfile index aee2bf8..26d8e74 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,92 +1,36 @@ -# This Dockerfile contains multiple targets. -# Use 'docker build --target= .' to build one. -# -# Every target has a BIN_NAME argument that must be provided via --build-arg=BIN_NAME= -# when building. +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 -ARG GO_VERSION=1.20 - -# =================================== -# -# Non-release images. -# -# =================================== - - -# dev-builder compiles the binary -# ----------------------------------- -FROM golang:$GO_VERSION as dev-builder - -ARG BIN_NAME +# Build the manager binary +FROM golang:1.20 as builder ARG TARGETOS ARG TARGETARCH -ENV BIN_NAME=$BIN_NAME - -WORKDIR /build - +WORKDIR /workspace +# Copy the Go Modules manifests COPY go.mod go.mod COPY go.sum go.sum - +# cache deps before building and copying source so that we don't need to re-download as much +# and so that source changes don't invalidate our downloaded layer RUN go mod download +# Copy the go source COPY main.go main.go COPY api/ api/ COPY controllers/ controllers/ -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -trimpath -o $BIN_NAME main.go - -# dev runs the binary from devbuild -# ----------------------------------- -FROM gcr.io/distroless/static:nonroot as dev - -ARG BIN_NAME -ARG PRODUCT_VERSION - -ENV BIN_NAME=$BIN_NAME - -LABEL version=$PRODUCT_VERSION +# 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 -trimpath -o manager main.go +# Use distroless as minimal base image to package the manager binary +# Refer to https://github.com/GoogleContainerTools/distroless for more details +FROM gcr.io/distroless/static:nonroot WORKDIR / -COPY --from=dev-builder /build/$BIN_NAME . -USER 65532:65532 - -ENTRYPOINT ["/$BIN_NAME"] - -# =================================== -# -# Release images. -# -# =================================== - - -# default release image -# ----------------------------------- -FROM gcr.io/distroless/static:nonroot AS release-default - -ARG BIN_NAME -ARG PRODUCT_VERSION -ARG PRODUCT_REVISION -ARG PRODUCT_NAME=$BIN_NAME -ARG TARGETOS -ARG TARGETARCH - -ENV BIN_NAME=$BIN_NAME - -LABEL maintainer="Team Terraform Ecosystem - Kubernetes " -LABEL version=$PRODUCT_VERSION -LABEL revision=$PRODUCT_REVISION - -COPY LICENSE /licenses/copyright.txt -COPY dist/$TARGETOS/$TARGETARCH/$BIN_NAME /bin/ - +COPY --from=builder /workspace/manager . USER 65532:65532 -ENTRYPOINT ["/$BIN_NAME"] - -# =================================== -# -# Set default target to 'dev'. -# -# =================================== -FROM dev +ENTRYPOINT ["/manager"] diff --git a/version/VERSION b/version/VERSION index 43b2961..8acdd82 100644 --- a/version/VERSION +++ b/version/VERSION @@ -1 +1 @@ -0.0.13 +0.0.1