Skip to content

Commit 12d6a07

Browse files
committed
Additional CI fixes
- Re-enable pre-commit - Re-enable building docker images - Remove outdated building of binaries - Improve Dockerfile for CI building When building multiplatform images the builds are happening simultaneously, therefore the cache should be partitioned by target platform to prevent races. - Make golangci-lint verbose
1 parent 655d86b commit 12d6a07

File tree

4 files changed

+70
-130
lines changed

4 files changed

+70
-130
lines changed

.circleci/config.yml

Lines changed: 63 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ orbs:
1919
executors:
2020
py:
2121
docker:
22-
- image: cimg/python:3.11.1-node@sha256:fac71c651914675c788807a3024d3730d897d3c898c47fa207268082fcba41c8
22+
- image: cimg/python:3.12.7-node
2323
environment:
2424
PIP_DISABLE_PIP_VERSION_CHECK: "1"
2525

@@ -56,7 +56,6 @@ jobs:
5656
- run:
5757
name: Prepare system
5858
command: |
59-
cp .circleci/.nodeenvrc ~
6059
cp .tool-versions ~
6160
- install-asdf
6261
- run:
@@ -120,7 +119,7 @@ jobs:
120119
- ~/.asdf
121120
- run: git diff --exit-code
122121

123-
rs-build:
122+
rs-test:
124123
parameters:
125124
go-version:
126125
type: string
@@ -175,90 +174,6 @@ jobs:
175174
paths:
176175
- "~/.cache/go-build"
177176

178-
build-docker-image:
179-
docker:
180-
- image: cimg/base:2023.08
181-
steps:
182-
- checkout
183-
- setup_remote_docker:
184-
docker_layer_caching: true
185-
- run:
186-
name: "Build docker image"
187-
command: |
188-
export DOCKER_BUILDKIT=1
189-
docker build -f docker/build-src/snapshot/Dockerfile -t snapshot:latest .
190-
- run:
191-
name: "Upload docker image"
192-
command: |
193-
TAG=ghcr.io/shutter-network/snapshot-$CIRCLE_BRANCH:$(git rev-list --count HEAD)
194-
echo "Uploading $TAG"
195-
echo $UPLOAD_GHCR_IO | docker login ghcr.io -u rolling-shutter-deployment --password-stdin
196-
docker tag snapshot:latest $TAG
197-
docker push $TAG
198-
199-
build-release:
200-
parameters:
201-
go-os-arch:
202-
type: string
203-
executor: go
204-
working_directory: ~/
205-
steps:
206-
- run:
207-
name: Configure environment for private repository
208-
command: |
209-
mkdir ~/.ssh; chmod 700 ~/.ssh
210-
echo >>~/.ssh/known_hosts github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
211-
git config --global url."git@github.com:shutter-network/rolling-shutter".insteadOf https://github.com/shutter-network/rolling-shutter
212-
echo >>${BASH_ENV} export GOPRIVATE=github.com/shutter-network/rolling-shutter/rolling-shutter
213-
- run:
214-
name: Configure environment
215-
command: |
216-
version=$(echo ${CIRCLE_TAG} | sed -e s#^rolling-shutter/##)
217-
test -z ${version} && version=${CIRCLE_SHA1}
218-
echo >>${BASH_ENV} export VERSION="${version}"
219-
220-
echo >>${BASH_ENV} osarch=<< parameters.go-os-arch >>
221-
# set GOOS, GOARCH from osarch:
222-
echo SUZTPSctJyByZWFkIC1yIEdPT1MgR09BUkNIIDw8PCAke29zYXJjaH0K |base64 --decode >>${BASH_ENV}
223-
echo >>${BASH_ENV} export GOOS GOARCH
224-
- run:
225-
name: Go install
226-
command: |
227-
env CGO_ENABLED=0 go install github.com/shutter-network/rolling-shutter/rolling-shutter@${CIRCLE_SHA1}
228-
- run:
229-
name: Copy binary
230-
command: |
231-
dst=${HOME}/release-bin/rolling-shutter-$GOOS-$GOARCH-$VERSION
232-
mkdir ${HOME}/release-bin
233-
if test -e ${HOME}/go/bin/rolling-shutter; then
234-
mv ${HOME}/go/bin/rolling-shutter ${dst}
235-
else
236-
mv ${HOME}/go/bin/${GOOS}_${GOARCH}/rolling-shutter ${dst}
237-
fi
238-
du -h ${dst}
239-
- persist_to_workspace:
240-
root: "~"
241-
paths:
242-
- "release-bin/"
243-
244-
publish-release:
245-
executor: go
246-
working_directory: ~/
247-
steps:
248-
- attach_workspace:
249-
at: ~/
250-
- run:
251-
name: Configure environment
252-
command: |
253-
version=$(echo ${CIRCLE_TAG} | sed -e s#^rolling-shutter/##)
254-
echo >>${BASH_ENV} export VERSION="${version}"
255-
- run: go install github.com/tcnksm/ghr@v0.14.0
256-
- run:
257-
name: Upload binaries
258-
command: |
259-
du -hc release-bin/*
260-
ghr -u shutter-network -r rolling-shutter ${CIRCLE_TAG} release-bin
261-
262177
rs-lint:
263178
executor: go
264179
resource_class: medium+
@@ -287,55 +202,82 @@ jobs:
287202
- "~/.cache/golangci-lint"
288203
- "~/.asdf"
289204

205+
build-docker-image:
206+
docker:
207+
- image: cimg/base:stable
208+
steps:
209+
- checkout
210+
- setup_remote_docker:
211+
docker_layer_caching: true
212+
- run:
213+
name: Configure Docker tag
214+
# Set the DOCKER_TAG environment variable based on the branch or tag.
215+
# Final release tags (i.e. without a, b, or rc) are only allowed on the "main" branch.
216+
command: |
217+
DOCKER_BASE=ghcr.io/shutter-network
218+
if [[ -z "$CIRCLE_TAG" ]]; then
219+
if [[ -z "$CIRCLE_PR_NUMBER" ]]; then
220+
DOCKER_TAG=${DOCKER_BASE}/unverified-dev-build-do-not-use:branch-${CIRCLE_BRANCH//\//_}-${CIRCLE_BUILD_NUM}
221+
else
222+
DOCKER_TAG=${DOCKER_BASE}/unverified-dev-build-do-not-use:PR${CIRCLE_PR_NUMBER}-${CIRCLE_BUILD_NUM}
223+
fi
224+
else
225+
if [[ $CIRCLE_BRANCH != "main" && ! $CIRCLE_TAG =~ (a|b|rc) ]]; then
226+
echo "Final release tags are only allowed on main branch."
227+
exit 1
228+
else
229+
DOCKER_TAG=${DOCKER_BASE}/keyper:${CIRCLE_TAG}
230+
fi
231+
fi
232+
echo "${DOCKER_TAG}"
233+
echo "DOCKER_TAG=${DOCKER_TAG}" >> $BASH_ENV
234+
- run:
235+
name: Docker login
236+
command: |
237+
echo $UPLOAD_GHCR_IO | docker login ghcr.io -u rolling-shutter-deployment --password-stdin
238+
- run:
239+
name: "Build and push docker image"
240+
command: |
241+
docker buildx create --use
242+
docker buildx build \
243+
--push \
244+
--progress plain \
245+
--platform linux/arm64,linux/amd64 \
246+
-f docker/build-src/rolling-shutter/Dockerfile \
247+
-t "${DOCKER_TAG}" \
248+
.
249+
290250
workflows:
291251
rolling-shutter:
292252
jobs:
293-
- build-docker-image:
253+
- pre-commit:
294254
filters:
295-
branches:
296-
only: /[a-z0-9]+/
297-
context:
298-
- upload-release
255+
tags:
256+
only: /.*/
257+
258+
- rs-lint:
259+
filters:
260+
tags:
261+
only: /.*/
262+
299263
- rs-generate:
300264
filters:
301265
tags:
302266
only: /.*/
303-
- rs-build:
267+
268+
- rs-test:
304269
matrix:
305270
parameters:
306271
go-version: [go-integration]
307272
filters:
308273
tags:
309274
only: /.*/
310-
- build-release:
311-
matrix:
312-
parameters:
313-
go-os-arch:
314-
[
315-
"linux-amd64",
316-
"linux-arm64",
317-
"freebsd-amd64",
318-
"openbsd-amd64",
319-
"darwin-amd64",
320-
"darwin-arm64",
321-
]
275+
276+
- build-docker-image:
277+
requires:
278+
- rs-lint
322279
filters:
323-
branches:
324-
ignore: /.*/
325280
tags:
326-
only: /^rolling-shutter\/v\d+\.\d+\.\d+$/
327-
- publish-release:
328-
requires:
329-
- rs-build
330-
- build-release
281+
only: /v[0-9]+\.[0-9]+.*/
331282
context:
332283
- upload-release
333-
filters:
334-
branches:
335-
ignore: /.*/
336-
tags:
337-
only: /^rolling-shutter\/v\d+\.\d+\.\d+$/
338-
- rs-lint:
339-
filters:
340-
branches:
341-
ignore: /main/

.pre-commit-config.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,13 @@ repos:
8383
exclude: |
8484
(?x)(
8585
^.*\.gen\.go$|
86-
^rolling-shutter/shmsg/.*\.pb\.go$|
87-
^rolling-shutter/p2pmsg/.*\.pb\.go$|
86+
^rolling-shutter/.*\.pb\.go$|
8887
^rolling-shutter/shcryptowasm/.*_wasm\.go$
8988
)
9089
- id: gofumpt
9190
exclude: |
9291
(?x)(
9392
^.*\.gen\.go$|
94-
^rolling-shutter/shmsg/.*\.pb\.go$|
95-
^rolling-shutter/p2pmsg/.*\.pb\.go$|
93+
^rolling-shutter/.*\.pb\.go$|
9694
^rolling-shutter/shcryptowasm/.*_wasm\.go$
9795
)

docker/build-src/rolling-shutter/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
FROM golang:1.21 as builder
1+
FROM golang:1.21 AS builder
22
ENV GOMODCACHE=/root/.cache/mod
33
# Fetch go modules separately to improve cache usage
44
RUN mkdir /gomod
55
COPY /rolling-shutter/go.* /gomod/
66
WORKDIR /gomod
7-
RUN --mount=type=cache,target=/root/.cache go mod download
7+
RUN --mount=type=cache,id=go-mod-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache go mod download
88

99
# Build binary
1010
COPY / /src
1111
WORKDIR /src/rolling-shutter
12-
RUN --mount=type=cache,target=/root/.cache CGO_ENABLED=1 GOOS=linux GOARCH=amd64 GOFLAGS=-v make build
12+
RUN --mount=type=cache,id=go-mod-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache CGO_ENABLED=1 GOOS=linux GOFLAGS=-v make build
1313

14-
FROM golang:1.21 as runner
14+
FROM golang:1.21 AS runner
1515

1616
COPY --from=builder /src/rolling-shutter/bin/rolling-shutter /rolling-shutter
1717

rolling-shutter/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ lint:
116116

117117
lint-changes:
118118
base=`git merge-base HEAD origin/main`; \
119-
golangci-lint run --new-from-rev $${base}
119+
golangci-lint --verbose run --new-from-rev $${base}
120120

121121
abigen:
122122
go generate -x ./contract

0 commit comments

Comments
 (0)