Skip to content

Commit 89c5d93

Browse files
committed
self-contained docker build
1 parent faf8635 commit 89c5d93

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

.circleci/config.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ jobs:
1818
steps:
1919
- checkout
2020
- run: make test
21+
verify:
22+
executor: golang
23+
steps:
24+
- checkout
25+
- run: make verify
2126
build:
2227
executor: golang
2328
working_directory: /work
@@ -64,14 +69,10 @@ jobs:
6469
- image: docker:stable
6570
working_directory: /work
6671
steps:
67-
- attach_workspace:
68-
at: /tmp/ct-monitor
6972
- setup_remote_docker:
7073
docker_layer_caching: false
7174
- checkout
7275
- run: |
73-
mkdir artifacts
74-
cp /tmp/ct-monitor/artifacts/ct-monitor-linux-amd64 artifacts/
7576
BASENAME="quay.io/hsn723/ct-monitor"
7677
TAG=$(cat VERSION)
7778
BRANCH=$(echo $TAG | cut -d '.' -f 1,2)
@@ -87,10 +88,12 @@ workflows:
8788
jobs:
8889
- lint
8990
- test
91+
- verify
9092
- build:
9193
requires:
9294
- lint
9395
- test
96+
- verify
9497
matrix:
9598
parameters:
9699
os: [linux]
@@ -106,7 +109,15 @@ workflows:
106109
only: master
107110
create-release:
108111
jobs:
112+
- verify:
113+
filters:
114+
branches:
115+
ignore: /.*/
116+
tags:
117+
only: /^v\d+\.\d+\.\d+$/
109118
- build:
119+
requires:
120+
- verify
110121
matrix:
111122
parameters:
112123
os: [linux, darwin, windows]
@@ -126,7 +137,7 @@ workflows:
126137
only: /^v\d+\.\d+\.\d+$/
127138
- publish-docker:
128139
requires:
129-
- build
140+
- verify
130141
filters:
131142
branches:
132143
ignore: /.*/

Dockerfile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
FROM quay.io/cybozu/ubuntu:20.04 as certs
1+
FROM quay.io/cybozu/golang:1.15-focal as build
2+
ENV CGO_ENABLED=0
3+
RUN mkdir -p /etc/ct-monitor /var/log/ct-monitor \
4+
&& chown nobody:nogroup /etc/ct-monitor /var/log/ct-monitor
5+
COPY . .
6+
RUN make
27

38
FROM scratch
4-
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
5-
COPY artifacts/ct-monitor-linux-amd64 /ct-monitor
9+
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
10+
COPY --from=build /etc/passwd /etc/passwd
11+
COPY --from=build /etc/group /etc/group
12+
COPY --from=build --chown=nobody:nogroup /etc/ct-monitor /etc/ct-monitor
13+
COPY --from=build --chown=nobody:nogroup /var/log/ct-monitor /var/log/ct-monitor
14+
COPY --from=build /tmp/ct-monitor/artifacts/ct-monitor-linux-amd64 /ct-monitor
15+
16+
USER nobody:nogroup
17+
618
ENTRYPOINT [ "/ct-monitor" ]

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
BUILD_DIR=/tmp/ct-monitor/artifacts
22
WORK_DIR=./bin
33
VERSION := $(shell cat VERSION)
4-
LDFLAGS=-ldflags "-X github.com/Hsn723/ct-monitor/cmd.CurrentVersion=${VERSION}"
4+
LDFLAGS=-ldflags "-w -s -X github.com/Hsn723/ct-monitor/cmd.CurrentVersion=${VERSION}"
55
OS ?= linux
66
ARCH ?= amd64
77
ifeq ($(OS), windows)
@@ -27,6 +27,11 @@ lint: clean setup
2727
test: clean
2828
go test -race -v ./...
2929

30+
.PHONY: verify
31+
verify:
32+
go mod download
33+
go mod verify
34+
3035
.PHONY: build
3136
build: clean setup
3237
env GOOS=$(OS) GOARCH=$(ARCH) go build $(LDFLAGS) -o $(BUILD_DIR)/ct-monitor-$(OS)-$(ARCH)$(EXT) .

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
0.1.1

0 commit comments

Comments
 (0)