Skip to content

Commit

Permalink
Publish multi-arch images with goreleaser (#509)
Browse files Browse the repository at this point in the history
##### ISSUE TYPE
 - Feature Pull Request

##### SUMMARY
- Switch to goreleaser for building and publishing release
- Set BotKube version with build args
- Use docker manifest to build multi-arch image
- Update CI pipeline to build and push image using goreleaser

Fixes #504 

```
$ docker manifest inspect ghcr.io/prasadg193/botkube:latest
{
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
   "manifests": [
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 1370,
         "digest": "sha256:64d94709256eb85452afa06aa15574724266fa6b82b70654ff6b03c467d5a5e4",
         "platform": {
            "architecture": "amd64",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 1160,
         "digest": "sha256:525d79e629637fd1ae3530223fa380aea26ed299a1fd9ae2787721f4cc33dad5",
         "platform": {
            "architecture": "amd64",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 1160,
         "digest": "sha256:ef72bc09078929c8aed1161f86c2c86523f6fac664094a034c737ffd582f3ea7",
         "platform": {
            "architecture": "arm64",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 1160,
         "digest": "sha256:990cd2c6b522a3a69ba73ee83ed0ae306102369f02d09891de8fbfd024d37e87",
         "platform": {
            "architecture": "arm",
            "os": "linux",
            "variant": "v7"
         }
      }
   ]
}

```
  • Loading branch information
PrasadG193 committed Aug 19, 2021
1 parent 6ced5ea commit f349853
Show file tree
Hide file tree
Showing 18 changed files with 285 additions and 259 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/artifacts.yml
@@ -0,0 +1,49 @@
name: build-artifacts
on:
push:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
env:
GO111MODULE: on
GOPATH: /home/runner/work/botkube
GOBIN: /home/runner/work/botkube/bin
DOCKER_CLI_EXPERIMENTAL: "enabled"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Docker Login
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser
run: make release_snapshot
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.4.0
- name: Update and publish helm chart
run: |
cd ..
git config --global user.email "botkube-ci@infracloud.io"
git config --global user.name "BotKube CI"
git clone https://github.com/infracloudio/charts.git
cd charts
git fetch
git branch
git pull origin gh-pages
helm package --app-version v9.99.9-dev --version v9.99.9-dev ${{ github.workspace }}/helm/botkube/
helm repo index --url https://infracloudio.github.io/charts --merge index.yaml .
git add .
git commit -m "Update BotKube latest helm chart"
git push https://${{ secrets.GH_TOKEN }}@github.com/infracloudio/charts.git
37 changes: 7 additions & 30 deletions .github/workflows/ci.yml
Expand Up @@ -11,9 +11,9 @@ jobs:
GOBIN: /home/runner/work/botkube/bin
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v1
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Install golint
Expand All @@ -32,33 +32,10 @@ jobs:
run: |
make test
make
- name: Build container image
run: make container-image
- name: Push docker images
if: success() && github.event_name == 'push' && endsWith(github.ref ,'develop')
run: |
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
docker push ghcr.io/infracloudio/botkube:latest
- name: Install helm
if: success() && github.event_name == 'push' && endsWith(github.ref ,'develop')
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.4.0
- name: Run helm lint
run: |
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh
chmod +x get_helm.sh
./get_helm.sh
helm lint helm/botkube
- name: Update and publish helm chart
if: success() && github.event_name == 'push' && endsWith(github.ref ,'develop')
run: |
cd ..
git config --global user.email "botkube-ci@infracloud.io"
git config --global user.name "BotKube CI"
git clone https://github.com/infracloudio/charts.git
cd charts
git fetch
git branch
git pull origin gh-pages
helm package --app-version v9.99.9-dev --version v9.99.9-dev ${{ github.workspace }}/helm/botkube/
helm repo index --url https://infracloudio.github.io/charts --merge index.yaml .
git add .
git commit -m "Update BotKube latest helm chart"
git push https://${{ secrets.GH_TOKEN }}@github.com/infracloudio/charts.git
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -15,3 +15,7 @@
vendor/
/.idea/
/botkube
/dist

# Tags
tags
58 changes: 58 additions & 0 deletions .goreleaser.yml
@@ -0,0 +1,58 @@
before:
hooks:
- go mod download
builds:
- id: botkube
binary: botkube
main: cmd/botkube/main.go
ldflags: &ldflags
- -s -w
-X github.com/infracloudio/botkube/pkg/version.Version={{ .Tag }}
-X github.com/infracloudio/botkube/pkg/version.GitCommitID={{ .Commit }}
-X github.com/infracloudio/botkube/pkg/version.BuildDate={{ .Date }}
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm
- arm64
goarm:
- 7
snapshot:
name_template: "{{ .Tag }}"
changelog:
skip: true
dockers:
- image_templates:
- 'ghcr.io/infracloudio/botkube:{{ .Tag }}-amd64'
use: buildx
dockerfile: 'build/Dockerfile'
build_flag_templates:
- "--platform=linux/amd64"
- "--build-arg=botkube_version={{ .Tag }}"
- image_templates:
- 'ghcr.io/infracloudio/botkube:{{ .Tag }}-arm64'
use: buildx
goarch: arm64
dockerfile: 'build/Dockerfile'
build_flag_templates:
- "--platform=linux/arm64"
- "--build-arg=botkube_version={{ .Tag }}"
- image_templates:
- 'ghcr.io/infracloudio/botkube:{{ .Tag }}-armv7'
use: buildx
goarch: arm
goarm: 7
dockerfile: 'build/Dockerfile'
build_flag_templates:
- "--platform=linux/arm"
- "--build-arg=botkube_version={{ .Tag }}"

docker_manifests:
- name_template: ghcr.io/infracloudio/botkube:{{ .Tag }}
image_templates:
- ghcr.io/infracloudio/botkube:{{ .Tag }}-amd64
- ghcr.io/infracloudio/botkube:{{ .Tag }}-arm64
- ghcr.io/infracloudio/botkube:{{ .Tag }}-armv7
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -33,7 +33,7 @@ Now you can build and run BotKube by one of the following ways
```sh
$ make build
$ make container-image
$ docker tag infracloudio/botkube:latest <your_account>/botkube:latest
$ docker tag infracloudio/botkube:latest-amd64 <your_account>/botkube:latest
$ docker push <your_account>/botkube:latest
```
Where `<your_account>` is Docker hub account to which you can push the image
Expand Down
29 changes: 13 additions & 16 deletions Makefile
Expand Up @@ -2,16 +2,16 @@ IMAGE_REPO=ghcr.io/infracloudio/botkube
TAG=$(shell cut -d'=' -f2- .release)

.DEFAULT_GOAL := build
.PHONY: release git-tag check-git-status build container-image pre-build tag-image publish test system-check
.PHONY: release git-tag check-git-status build pre-build publish test system-check

# Show this help.
help:
@awk '/^#/{c=substr($$0,3);next}c&&/^[[:alpha:]][[:alnum:]_-]+:/{print substr($$1,1,index($$1,":")),c}1{c=0}' $(MAKEFILE_LIST) | column -s: -t

# Docker Tasks
# Make a release
release: check-git-status test container-image tag-image publish git-tag
@echo "Successfully releeased version $(TAG)"
release: check-git-status test git-tag gorelease
@echo "Successfully released version $(TAG)"

# Create a git tag
git-tag:
Expand Down Expand Up @@ -42,9 +42,18 @@ build: pre-build
# Build the image
container-image: pre-build
@echo "Building docker image"
@docker build --build-arg GOOS_VAL=$(shell go env GOOS) --build-arg GOARCH_VAL=$(shell go env GOARCH) -t $(IMAGE_REPO) -f build/Dockerfile --no-cache .
@./hack/goreleaser.sh build
@echo "Docker image build successfully"

# Publish release using goreleaser
gorelease:
@echo "Publishing release with goreleaser"
@./hack/goreleaser.sh release

# Build project and push dev images with latest tag
release-snapshot:
@./hack/goreleaser.sh release_snapshot

# system checks
system-check:
@echo "Checking system information"
Expand All @@ -60,18 +69,6 @@ system-check:
# Pre-build checks
pre-build: system-check

# Tag images
tag-image:
@echo 'Tagging image'
@docker tag $(IMAGE_REPO) $(IMAGE_REPO):$(TAG)

# Docker push image
publish:
@echo "Pushing docker image to repository"
@docker login
@docker push $(IMAGE_REPO):$(TAG)
@docker push $(IMAGE_REPO):latest

# Create KIND cluster
create-kind: system-check
@./hack/kind-cluster.sh create-kind
Expand Down
47 changes: 13 additions & 34 deletions build/Dockerfile
Expand Up @@ -17,44 +17,23 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# Development image
FROM golang:1.16-alpine3.12 AS BUILD-ENV

ARG GOOS_VAL
ARG GOARCH_VAL

# Add git curl and gcc
RUN apk update && apk add git curl build-base

WORKDIR /app

# Download dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy source
COPY . .

# Build binary
RUN GOOS=${GOOS_VAL} GOARCH=${GOARCH_VAL} go build -o /go/bin/botkube ./cmd/botkube

# Install kubectl binary
RUN apk add --no-cache ca-certificates git \
&& wget -q https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl -O /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl

# Production image
FROM alpine:3.12
ARG botkube_version="dev"
LABEL name="botkube" \
version="${botkube_version}" \
release="${botkube_version}" \
summary="BotKube is a messaging bot for monitoring and debugging Kubernetes clusters" \
maintainer="Prasad Ghangal<prasad.ghangal@gmail.com>" \
description="BotKube is a messaging bot for monitoring and debugging Kubernetes clusters"

COPY botkube /usr/local/bin/botkube
COPY --from=bitnami/kubectl /opt/bitnami/kubectl/bin/kubectl /usr/local/bin/kubectl

# Create Non Privileged user
RUN addgroup --gid 101 botkube && \
adduser -S --uid 101 --ingroup botkube botkube
RUN addgroup --gid 1001 botkube && \
adduser -S --uid 1001 --ingroup botkube botkube

# Run as Non Privileged user
USER botkube

COPY --from=BUILD-ENV /go/bin/botkube /go/bin/botkube
COPY --from=BUILD-ENV /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=BUILD-ENV /usr/local/bin/kubectl /usr/local/bin/kubectl

ENTRYPOINT /go/bin/botkube
ENTRYPOINT /usr/local/bin/botkube
3 changes: 0 additions & 3 deletions deploy-all-in-one-tls.yaml
Expand Up @@ -380,9 +380,6 @@ spec:
# set one of the log levels- info, warn, debug, error, fatal, panic
- name: LOG_LEVEL
value: "info"
# set BotKube release version
- name: BOTKUBE_VERSION
value: v0.12.1
volumes:
- name: config-volume
projected:
Expand Down
3 changes: 0 additions & 3 deletions deploy-all-in-one.yaml
Expand Up @@ -368,9 +368,6 @@ spec:
# set one of the log levels- info, warn, debug, error, fatal, panic
- name: LOG_LEVEL
value: "info"
# set BotKube release version
- name: BOTKUBE_VERSION
value: v0.12.1
volumes:
- name: config-volume
projected:
Expand Down

0 comments on commit f349853

Please sign in to comment.