Skip to content

Commit

Permalink
feat: build using werf
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Mikheykin <[email protected]>
  • Loading branch information
diafour committed May 18, 2023
1 parent 3ee96e2 commit b6d2ccd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 36 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ test

.git
.gitignore
Dockerfile
LICENSE
*.md
*.png
40 changes: 22 additions & 18 deletions .github/workflows/publish-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ jobs:
id: check
with:
script: |
const PUBLISH_DEV_LABEL = 'publish/image/dev';
const PUBLISH_FULL_LABEL = 'publish/image/dev/full';
const PUBLISH_AMD64_LABEL = 'publish/image/dev/amd64';
const labelName = context.payload.label.name;
let runPublish = false;
let buildMultiArch = false;
if (labelName === PUBLISH_DEV_LABEL) {
if (labelName === PUBLISH_FULL_LABEL) {
runPublish = true;
buildMultiArch = true;
}
Expand Down Expand Up @@ -77,14 +77,16 @@ jobs:
: Image name and version for dev image
# Example: dev-feat_branch-371e2d3b-2020.02.06_18:37:42
APP_VERSION=dev-${GITHUB_REF#refs/heads/}-${GITHUB_SHA::8}-$(date +'%Y.%m.%d_%H:%M:%S')
GHCR_IO_IMAGE_NAME="${GHCR_IO_REPO}:pr${{ github.event.pull_request.number }}"
IMAGE_TAG="pr${{ github.event.pull_request.number }}"
GHCR_IO_IMAGE_NAME="${GHCR_IO_REPO}:${IMAGE_TAG}"
echo "APP_VERSION=${APP_VERSION}" >> ${GITHUB_ENV}
echo "GHCR_IO_IMAGE_NAME=${GHCR_IO_IMAGE_NAME}" >> ${GITHUB_ENV}
echo "========================================="
echo "APP_VERSION = $APP_VERSION"
echo "GHCR_IO_IMAGE_NAME = $GHCR_IO_IMAGE_NAME"
echo "APP_VERSION = $APP_VERSION"
echo "IMAGE_TAG = $IMAGE_TAG"
echo "GHCR_IO_IMAGE_NAME = $GHCR_IO_IMAGE_NAME"
echo "========================================="
if [[ ${BUILD_MULTI_ARCH} == "false" ]] ; then
Expand All @@ -94,17 +96,14 @@ jobs:
echo "BUILDX_PLATFORMS = ${BUILDX_PLATFORMS}"
echo "========================================="
- name: Set up QEMU
- name: Setup qemu
if: needs.check.outputs.build_multi_arch == 'true'
uses: docker/[email protected]
with:
platforms: "${{ env.QEMU_PLATFORMS }}"

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
version: latest
- name: Setup werf
uses: werf/actions/[email protected]

- name: Login to Github Container Registry
uses: docker/[email protected]
Expand All @@ -113,14 +112,19 @@ jobs:
username: ${{ secrets.GHCR_IO_USER }}
password: ${{ secrets.GHCR_IO_PASS }}

- name: Build and push using buildx
- name: Build and push
run: |
echo "Build ${GHCR_IO_IMAGE_NAME} with version '${APP_VERSION}'"
docker buildx build \
--platform $BUILDX_PLATFORMS \
--build-arg appVersion=$APP_VERSION \
--tag $GHCR_IO_IMAGE_NAME \
--push .
echo "Build ${GHCR_IO_IMAGE_NAME} with version '${APP_VERSION}' and tag '${IMAGE_TAG}'"
source "$(werf ci-env github --as-file)"
werf build --repo ${GHCR_IO_REPO} --add-custom-tag '${IMAGE_TAG}'
# docker buildx build \
# --platform $BUILDX_PLATFORMS \
# --build-arg appVersion=$APP_VERSION \
# --tag $GHCR_IO_IMAGE_NAME \
# --push .

- name: Inspect binaries
if: needs.check.outputs.build_multi_arch == 'true'
Expand Down
38 changes: 21 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
# Prebuilt libjq.
FROM --platform=${TARGETPLATFORM:-linux/amd64} flant/jq:b6be13d5-musl as libjq
FROM flant/jq:b6be13d5-musl as libjq

# Go builder.
FROM --platform=${TARGETPLATFORM:-linux/amd64} golang:1.20-alpine3.16 AS builder
FROM golang:1.20-alpine3.18 AS builder

ARG appVersion=latest
RUN apk --no-cache add git ca-certificates gcc musl-dev libc-dev
RUN echo appversion=$appVersion
#RUN apk --no-cache add git ca-certificates gcc musl-dev libc-dev

# Cache-friendly download of go dependencies.
ADD go.mod go.sum /app/
WORKDIR /app
RUN go mod download
#RUN go mod download

COPY --from=libjq /libjq /libjq
ADD . /app

RUN CGO_ENABLED=1 \
CGO_CFLAGS="-I/libjq/include" \
CGO_LDFLAGS="-L/libjq/lib" \
GOOS=linux \
go build -ldflags="-linkmode external -extldflags '-static' -s -w -X 'github.com/flant/shell-operator/pkg/app.Version=$appVersion'" \
-tags use_libjq \
-o shell-operator \
./cmd/shell-operator
RUN touch shell-operator

#RUN CGO_ENABLED=1 \
# CGO_CFLAGS="-I/libjq/include" \
# CGO_LDFLAGS="-L/libjq/lib" \
# GOOS=linux \
# go build -ldflags="-linkmode external -extldflags '-static' -s -w -X 'github.com/flant/shell-operator/pkg/app.Version=$appVersion'" \
# -tags use_libjq \
# -o shell-operator \
# ./cmd/shell-operator

# Final image
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.18
FROM alpine:3.18
ARG TARGETPLATFORM
RUN apk --no-cache add ca-certificates bash sed tini && \
kubectlArch=$(echo ${TARGETPLATFORM:-linux/amd64} | sed 's/\/v7//') && \
echo "Download kubectl for ${kubectlArch}" && \
wget https://storage.googleapis.com/kubernetes-release/release/v1.21.10/bin/${kubectlArch}/kubectl -O /bin/kubectl && \
chmod +x /bin/kubectl && \
echo "TARGETPLATFORM=${TARGETPLATFORM}" && \
# kubectlArch=$(echo ${TARGETPLATFORM:-linux/amd64} | sed 's/\/v7//') && \
# echo "Download kubectl for ${kubectlArch}" && \
# wget https://storage.googleapis.com/kubernetes-release/release/v1.21.10/bin/${kubectlArch}/kubectl -O /bin/kubectl && \
# chmod +x /bin/kubectl && \
mkdir /hooks
ADD frameworks/shell /frameworks/shell
ADD shell_lib.sh /
Expand Down
12 changes: 12 additions & 0 deletions werf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
project: shell-operator
configVersion: 1
build:
platforms:
- linux/amd64
- linux/arm64
---
image: main
dockerfile: Dockerfile
staged: true
args:
appVersion: {{ env "APP_VERSION" }}

0 comments on commit b6d2ccd

Please sign in to comment.