From 6779b506e9c5efcc51e60a083067e70ca5272085 Mon Sep 17 00:00:00 2001 From: "itamar.marom" Date: Fri, 2 Feb 2024 22:15:39 +0200 Subject: [PATCH 1/3] init --- .github/workflows/release.yml | 96 +++++++++++++++++++++++++++++++++++ Dockerfile | 10 +++- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..e35f9084 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,96 @@ +name: Release + +on: + push: + tags: + - '*' + +env: + CONTROLLER: ${{ github.event.repository.name }} + IMAGE_REPOSITORY: "docker.io/datainfrahq" + +jobs: + build-and-push-image: + name: Build and Push Docker Image + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Prepare + id: prep + run: | + VERSION="${{ github.event.inputs.tag }}-${GITHUB_SHA::8}" + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF/refs\/tags\//} + fi + echo ::set-output name=BUILD_DATE::$(date -u +'%Y-%m-%dT%H:%M:%SZ') + echo ::set-output name=VERSION::${VERSION} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: / + tags: | + type=semver,pattern={{version}} + + - name: Build and Push Image + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + package-and-release-chart: + name: Package and Release Helm Chart + needs: build-and-push-image + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Configure Git + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + + - name: Install Helm + uses: azure/setup-helm@v1 + + - name: Package Helm Chart + run: | + helm package charts/ --version ${{ github.ref_name }} --app-version ${{ github.ref_name }} + working-directory: . + + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref_name }} + release_name: Release ${{ github.ref_name }} + draft: false + prerelease: false + + - name: Upload Helm Chart to Release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./${{ github.ref_name }}-.tgz + asset_name: .tgz + asset_content_type: application/octet-stream \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e2f89ddd..f880e9e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,8 @@ FROM golang:1.20 as builder ARG TARGETOS ARG TARGETARCH +ARG BUILD_SHA +ARG BUILD_VERSION WORKDIR /workspace # Copy the Go Modules manifests @@ -21,11 +23,17 @@ COPY controllers/ controllers/ # 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 -gcflags=all="-N -l" \ + -ldflags "-X main.BuildSHA='${BUILD_SHA}' -X main.BuildVersion='${BUILD_VERSION}'" \ + -a -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 + +LABEL org.opencontainers.image.source="https://github.com/datainfrahq/druid-operator" + WORKDIR / COPY --from=builder /workspace/manager . USER 65532:65532 From 136351a46e151083ab2364e35a22f0585abf116d Mon Sep 17 00:00:00 2001 From: "itamar.marom" Date: Sat, 20 Apr 2024 14:24:41 +0300 Subject: [PATCH 2/3] chore(ci): add release.yml --- .github/workflows/release.yml | 63 +++++++++-------------------------- 1 file changed, 16 insertions(+), 47 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e35f9084..fd0f62a4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,10 +3,9 @@ name: Release on: push: tags: - - '*' + - 'v*' env: - CONTROLLER: ${{ github.event.repository.name }} IMAGE_REPOSITORY: "docker.io/datainfrahq" jobs: @@ -17,6 +16,11 @@ jobs: - name: Check out code uses: actions/checkout@v2 + - name: Configure Git + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + - name: Prepare id: prep run: | @@ -24,8 +28,8 @@ jobs: if [[ $GITHUB_REF == refs/tags/* ]]; then VERSION=${GITHUB_REF/refs\/tags\//} fi - echo ::set-output name=BUILD_DATE::$(date -u +'%Y-%m-%dT%H:%M:%SZ') - echo ::set-output name=VERSION::${VERSION} + echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT" + echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT" - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -36,43 +40,13 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v3 + - name: Set up Go + uses: actions/setup-go@v3 with: - images: / - tags: | - type=semver,pattern={{version}} + go-version: '1.20' - - name: Build and Push Image - uses: docker/build-push-action@v2 - with: - context: . - file: ./Dockerfile - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - package-and-release-chart: - name: Package and Release Helm Chart - needs: build-and-push-image - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v2 - - - name: Configure Git - run: | - git config user.name "GitHub Actions" - git config user.email "actions@github.com" - - - name: Install Helm - uses: azure/setup-helm@v1 - - - name: Package Helm Chart - run: | - helm package charts/ --version ${{ github.ref_name }} --app-version ${{ github.ref_name }} - working-directory: . + - name: Build and push operator image with Buildx + run: make docker-buildx IMG="${IMAGE_REPOSITORY}:${{ steps.prep.outputs.VERSION }}" - name: Create GitHub Release id: create_release @@ -85,12 +59,7 @@ jobs: draft: false prerelease: false - - name: Upload Helm Chart to Release - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Publish Helm chart in GitHub Pages + uses: stefanprodan/helm-gh-pages@v1.7.0 with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./${{ github.ref_name }}-.tgz - asset_name: .tgz - asset_content_type: application/octet-stream \ No newline at end of file + token: ${{ secrets.GITHUB_TOKEN }} From cc65d96a8e56b15772b052515818d65f29b4c3a2 Mon Sep 17 00:00:00 2001 From: "itamar.marom" Date: Sat, 20 Apr 2024 14:28:06 +0300 Subject: [PATCH 3/3] chore(dockerfile): revert back --- Dockerfile | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index f880e9e4..e2f89ddd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,6 @@ FROM golang:1.20 as builder ARG TARGETOS ARG TARGETARCH -ARG BUILD_SHA -ARG BUILD_VERSION WORKDIR /workspace # Copy the Go Modules manifests @@ -23,17 +21,11 @@ COPY controllers/ controllers/ # 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 -gcflags=all="-N -l" \ - -ldflags "-X main.BuildSHA='${BUILD_SHA}' -X main.BuildVersion='${BUILD_VERSION}'" \ - -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -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 - -LABEL org.opencontainers.image.source="https://github.com/datainfrahq/druid-operator" - WORKDIR / COPY --from=builder /workspace/manager . USER 65532:65532