Skip to content

Commit

Permalink
Add workflow to build and consume kopia binary in kanister-tools (#1611)
Browse files Browse the repository at this point in the history
* Add workflow to build and consume kopia binary in kanister-tools

Signed-off-by: Ankit Jain <ankitjain.meone@gmail.com>

* Address review comments - update Copyright comment

* Revert changes in kanister-tools Dockerfile

* Remove timestamp for Dockerfile to avoid sha update on every build

* Add Github Action to update kopia image and raise PR to update Kanister tools Dockerfile

* Revert "Add Github Action to update kopia image and raise PR to update Kanister tools Dockerfile"

This reverts commit 5434adb.

* Add comment, update variable name

* Address review comment - remove duplicate, unnecessary lines

* Update kopia build Dockerfile to use goreleaser

* Use goreleaser docker image to get binary

* Update base image versions

Signed-off-by: Ankit Jain <ankitjain.meone@gmail.com>
Co-authored-by: Pavan Navarathna <6504783+pavannd1@users.noreply.github.com>
  • Loading branch information
ankitjain235 and pavannd1 authored Sep 7, 2022
1 parent 09018c8 commit 0503369
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: tar -xvf ./src.tar.gz
- run: make update-kopia-image
- run: make release-snapshot
- run: ./build/push_images.sh
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ DOCKER_CONFIG ?= "$(HOME)/.docker"

# Mention the vm-driver that should be used to install OpenShift
vm-driver ?= "kvm"

# Refers to https://github.com/kopia/kopia/commit/317cc36892707ab9bdc5f6e4dea567d1e638a070
KOPIA_COMMIT_ID ?= "317cc36"

KOPIA_REPO ?= "kopia"
# Default OCP version in which the OpenShift apps are going to run
ocp_version ?= "4.10"
###
Expand Down Expand Up @@ -257,6 +262,9 @@ gorelease:
release-snapshot:
@$(MAKE) run CMD='-c "GORELEASER_CURRENT_TAG=v9.99.9-dev goreleaser --debug release --rm-dist --snapshot"'

update-kopia-image:
@/bin/bash ./build/update_kopia_image.sh $(KOPIA_COMMIT_ID) $(KOPIA_REPO)

go-mod-download:
@$(MAKE) run CMD='-c "go mod download"'

Expand Down
36 changes: 36 additions & 0 deletions build/update_kopia_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Copyright 2022 The Kanister Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset

IMAGE_REGISTRY="ghcr.io/kanisterio"

readonly COMMIT_ID=${1:?"Commit id to build kopia image not specified"}
readonly KOPIA_REPO_ORG=${2-:"kopia"}
readonly IMAGE_TYPE=alpine
readonly IMAGE_BUILD_VERSION="${COMMIT_ID}"
readonly GH_PACKAGE_TARGET="${IMAGE_REGISTRY}/kopia"
readonly TAG="${IMAGE_TYPE}-${IMAGE_BUILD_VERSION}"


docker build \
--tag "${GH_PACKAGE_TARGET}:${TAG}" \
--build-arg "kopiaBuildCommit=${COMMIT_ID}" \
--build-arg "kopiaRepoOrg=${KOPIA_REPO_ORG}" \
--file ./docker/kopia-build/Dockerfile .

docker push ${GH_PACKAGE_TARGET}:$TAG
45 changes: 45 additions & 0 deletions docker/kopia-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM golang:1.19.1-alpine3.16 AS builder

ARG kopiaBuildCommit
ARG kopiaRepoOrg

RUN apk add git

WORKDIR /

RUN git clone https://github.com/${kopiaRepoOrg}/kopia.git

ENV GITHUB_REPOSITORY=https://github.com/${kopiaRepoOrg}/kopia

WORKDIR /kopia

# Build kopia binary from specific commit
RUN git checkout ${kopiaBuildCommit}
# Refers to goreleaser/goreleaser:v1.11.2
COPY --from=docker.io/goreleaser/goreleaser@sha256:b13418f20019fffb29797aff3d03f5e9ca84cea93634f4169a7ed603a95ab198 \
/usr/bin/goreleaser /usr/bin/goreleaser
RUN goreleaser build --output=. --rm-dist --single-target

RUN adduser -D kopia && addgroup kopia kopia
USER kopia:kopia

COPY --chown=kopia . /kopia

FROM alpine:3.16

WORKDIR /kopia

# Add CA certs
RUN apk add --no-cache --verbose ca-certificates && \
rm -rf /var/cache/apk/* && \
adduser -D kopia && addgroup kopia kopia && \
chown kopia /kopia

USER kopia:kopia

ENTRYPOINT [ "/kopia/kopia" ]

LABEL imageVersion="${imageVersion}"
LABEL kopiaBuildCommit="${kopiaBuildCommit}"

COPY --from=builder --chown=kopia:kopia /kopia/kopia /kopia/kopia

0 comments on commit 0503369

Please sign in to comment.