Skip to content

Commit b6db59c

Browse files
author
Farhan Khan
committed
chore(ci): update docker image and build prod images
- build from go 1.18 base image - build from distroless image - update push CI pipeline to build all dist binaries - update push CI to create docker image - add pull CI pipeline to run tests for every PR
1 parent b96e378 commit b6db59c

File tree

4 files changed

+114
-15
lines changed

4 files changed

+114
-15
lines changed

.github/workflows/pull.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: pullCI
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
name: build-and-test
8+
strategy:
9+
matrix:
10+
include:
11+
- os: ubuntu-latest
12+
go: "1.18"
13+
test: true
14+
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- uses: actions/setup-go@v3
18+
with:
19+
go-version: ${{ matrix.go }}
20+
21+
- uses: actions/checkout@v3
22+
23+
- name: Test
24+
run: make test
25+
if: matrix.test

.github/workflows/push.yml

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
name: CI
2-
on: [push]
1+
name: pushCI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- release/v*
8+
tags:
9+
- 'v*'
10+
311
jobs:
412
build-linux:
513
name: Build
@@ -21,6 +29,7 @@ jobs:
2129
run: |
2230
make test
2331
shell: bash
32+
2433
build-windows:
2534
name: Build
2635
strategy:
@@ -38,3 +47,68 @@ jobs:
3847
env:
3948
GO111MODULE: "on"
4049
run: make all
50+
51+
binaries:
52+
name: Build binaries and notarize sources
53+
needs:
54+
- build-windows
55+
- build-linux
56+
runs-on: ubuntu-latest
57+
env:
58+
JOB_NAME: ${{ github.job }}
59+
JOB_ID: ${{ github.run_id }}
60+
outputs:
61+
matrix: ${{ steps.list-binaries.outputs.matrix }}
62+
steps:
63+
- uses: actions/setup-go@v3
64+
with:
65+
go-version: ${{ env.GO_VERSION }}
66+
- uses: actions/checkout@v3
67+
- name: Build binaries
68+
run: make dist
69+
- id: list-binaries
70+
run: |
71+
echo "::set-output name=matrix::$(ls dist | jq -R -s -c 'split("\n")[:-1] | {binary: .}')"
72+
- name: Upload binary artifacts
73+
uses: actions/upload-artifact@v3
74+
with:
75+
name: immugw-binaries
76+
path: dist
77+
retention-days: 5
78+
- name: Calculate checksums
79+
run: make dist/binary.md
80+
81+
images:
82+
name: Build and notarize Docker Images
83+
needs:
84+
- binaries
85+
runs-on: ubuntu-latest
86+
env:
87+
JOB_NAME: ${{ github.job }}
88+
JOB_ID: ${{ github.run_id }}
89+
DOCKER_IMAGE_IMMUGW: "codenotary/immugw"
90+
DOCKER_BUILDKIT: "1"
91+
steps:
92+
- uses: actions/checkout@v3
93+
- name: Build docker images
94+
shell: bash
95+
run: |
96+
if [[ "${GITHUB_REF}" =~ ^refs/tags/v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
97+
VERSION_TAG="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}"
98+
VERSION_TAG_SHORT="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
99+
fi
100+
101+
docker build --tag "${DOCKER_IMAGE_IMMUGW}:dev" -f Dockerfile .
102+
103+
docker login -u "${{ secrets.REGISTRY_USER }}" -p "${{ secrets.REGISTRY_PASS }}"
104+
105+
docker push "${DOCKER_IMAGE_IMMUGW}:dev"
106+
107+
if [[ ! -z "$VERSION_TAG" ]]; then
108+
for tag in "${VERSION_TAG}" "${VERSION_TAG_SHORT}" "latest"; do
109+
docker tag "${DOCKER_IMAGE_IMMUGW}:dev" "${DOCKER_IMAGE_IMMUGW}:${tag}"
110+
docker push "${DOCKER_IMAGE_IMMUGW}:${tag}"
111+
done
112+
fi
113+
114+
docker logout

Dockerfile

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
FROM golang:1.13-stretch as build
1+
FROM golang:1.18 as build
22
WORKDIR /src
3+
COPY go.mod go.sum /src/
4+
RUN go mod download
35
COPY . .
46
RUN GOOS=linux GOARCH=amd64 make immugw-static
5-
FROM ubuntu:18.04
6-
MAINTAINER vChain, Inc. <[email protected]>
7+
RUN mkdir /empty
78

8-
COPY --from=build /src/immugw /usr/sbin/immugw
9+
FROM gcr.io/distroless/base:nonroot
10+
LABEL org.opencontainers.image.authors="Codenotary Inc. <[email protected]>"
911

10-
ARG IMMU_UID="3323"
11-
ARG IMMU_GID="3323"
12+
WORKDIR /usr/sbin
13+
COPY --from=build /src/immugw /usr/sbin/immugw
1214

1315
ENV IMMUGW_DIR="/var/lib/immudb" \
1416
IMMUGW_ADDRESS="0.0.0.0" \
@@ -24,16 +26,10 @@ ENV IMMUGW_DIR="/var/lib/immudb" \
2426
IMMUGW_AUDIT_USERNAME="" \
2527
IMMUGW_AUDIT_PASSWORD=""
2628

27-
RUN addgroup --system --gid $IMMU_GID immu && \
28-
adduser --system --uid $IMMU_UID --no-create-home --ingroup immu immu && \
29-
mkdir -p "$IMMUGW_DIR" && \
30-
chown -R immu:immu "$IMMUGW_DIR" && \
31-
chmod -R 777 "$IMMUGW_DIR" && \
32-
chmod +x /usr/sbin/immugw
29+
COPY --from=build --chown=nonroot:nonroot /empty "$IMMUGW_DIR"
3330

3431
EXPOSE 3323
3532
EXPOSE 9476
3633

3734
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "/usr/sbin/immugw", "version" ]
38-
USER immu
3935
ENTRYPOINT ["/usr/sbin/immugw"]

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,8 @@ dist/binary.md:
100100
printf "[$$ff](https://github.com/codenotary/immugw/releases/download/v${VERSION}/$$ff) | $$shm_id \n" ; \
101101
done
102102

103+
.PHONY: dist
104+
dist: dist/binaries
105+
@echo 'Binaries generation complete. Now vcn signature is needed.'
106+
103107
########################## releases scripts end ########################################################################

0 commit comments

Comments
 (0)