Skip to content

Commit f215ca4

Browse files
committed
update build system and lint
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
1 parent 36ae237 commit f215ca4

File tree

17 files changed

+474
-119
lines changed

17 files changed

+474
-119
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/
2+
/go-replace
3+
/example
4+
/release-assets

.editorconfig

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
# top-most EditorConfig file
44
root = true
5-
charset = utf-8
6-
trim_trailing_whitespace = true
75

86
[*]
7+
charset = utf-8
8+
trim_trailing_whitespace = true
99
end_of_line = lf
1010
insert_final_newline = true
1111
indent_style = space
@@ -14,16 +14,38 @@ indent_size = 4
1414
[Makefile]
1515
indent_style = tab
1616

17-
[*.yml]
17+
[{*.yml, *.yaml}]
1818
indent_size = 2
1919

2020
[*.conf]
2121
indent_size = 2
2222

23-
[*.t]
24-
indent_size = 2
25-
trim_trailing_whitespace = false
26-
2723
[*.go]
28-
indent_style = tab
2924
indent_size = 4
25+
indent_style = tab
26+
ij_continuation_indent_size = 4
27+
ij_go_GROUP_CURRENT_PROJECT_IMPORTS = true
28+
ij_go_add_leading_space_to_comments = true
29+
ij_go_add_parentheses_for_single_import = true
30+
ij_go_call_parameters_new_line_after_left_paren = true
31+
ij_go_call_parameters_right_paren_on_new_line = true
32+
ij_go_call_parameters_wrap = off
33+
ij_go_fill_paragraph_width = 80
34+
ij_go_group_stdlib_imports = true
35+
ij_go_import_sorting = goimports
36+
ij_go_keep_indents_on_empty_lines = false
37+
ij_go_local_group_mode = project
38+
ij_go_move_all_imports_in_one_declaration = true
39+
ij_go_move_all_stdlib_imports_in_one_group = true
40+
ij_go_remove_redundant_import_aliases = false
41+
ij_go_run_go_fmt_on_reformat = true
42+
ij_go_use_back_quotes_for_imports = false
43+
ij_go_wrap_comp_lit = off
44+
ij_go_wrap_comp_lit_newline_after_lbrace = true
45+
ij_go_wrap_comp_lit_newline_before_rbrace = true
46+
ij_go_wrap_func_params = off
47+
ij_go_wrap_func_params_newline_after_lparen = true
48+
ij_go_wrap_func_params_newline_before_rparen = true
49+
ij_go_wrap_func_result = off
50+
ij_go_wrap_func_result_newline_after_lparen = true
51+
ij_go_wrap_func_result_newline_before_rparen = true

.github/workflows/ci-docker.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: "CI docker"
2+
3+
on: [pull_request, workflow_dispatch]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
11+
- name: Set Swap Space
12+
uses: pierotofy/set-swap-space@master
13+
with:
14+
swap-size-gb: 12
15+
16+
- name: Run Golangci lint
17+
uses: golangci/golangci-lint-action@v2
18+
with:
19+
version: latest
20+
args: --print-resources-usage
21+
22+
- name: Docker meta
23+
id: docker_meta
24+
uses: docker/metadata-action@v3
25+
with:
26+
images: ${{ github.repository }},quay.io/${{ github.repository }}
27+
labels: |
28+
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/${{ github.event.repository.default_branch }}/README.md
29+
30+
- name: Set up QEMU
31+
uses: docker/setup-qemu-action@v1
32+
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v1
35+
36+
- name: Build
37+
uses: docker/build-push-action@v2
38+
with:
39+
context: .
40+
file: ./Dockerfile
41+
push: false
42+
platforms: linux/amd64,linux/arm64,linux/arm
43+
tags: ${{ steps.docker_meta.outputs.tags }}
44+
labels: ${{ steps.docker_meta.outputs.labels }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: "Release: assets"
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Set Swap Space
14+
uses: pierotofy/set-swap-space@master
15+
with:
16+
swap-size-gb: 12
17+
18+
- uses: actions/setup-go@v2
19+
with:
20+
go-version: '1.19'
21+
check-latest: true
22+
23+
- name: Build
24+
run: |
25+
make release-assets
26+
27+
- name: Upload assets to release
28+
uses: svenstaro/upload-release-action@v2
29+
with:
30+
repo_token: ${{ secrets.GITHUB_TOKEN }}
31+
file: ./release-assets/*
32+
tag: ${{ github.ref }}
33+
overwrite: true
34+
file_glob: true
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: "Release: docker"
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
tags:
8+
- '*.*.*'
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Set Swap Space
17+
uses: pierotofy/set-swap-space@master
18+
with:
19+
swap-size-gb: 12
20+
21+
- name: Run Golangci lint
22+
uses: golangci/golangci-lint-action@v2
23+
with:
24+
version: latest
25+
args: --print-resources-usage
26+
27+
build:
28+
needs: lint
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
Dockerfile: [Dockerfile]
33+
suffix: [""]
34+
latest: ["auto"]
35+
include: []
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v2
39+
40+
- name: Set Swap Space
41+
uses: pierotofy/set-swap-space@master
42+
with:
43+
swap-size-gb: 12
44+
45+
- name: Docker meta
46+
id: docker_meta
47+
uses: docker/metadata-action@v4
48+
with:
49+
images: ${{ github.repository }},quay.io/${{ github.repository }}
50+
labels: |
51+
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/${{ github.event.repository.default_branch }}/README.md
52+
flavor: |
53+
latest=${{ matrix.latest }}
54+
suffix=${{ matrix.suffix }}
55+
56+
- name: Set up QEMU
57+
uses: docker/setup-qemu-action@v1
58+
59+
- name: Set up Docker Buildx
60+
uses: docker/setup-buildx-action@v1
61+
62+
- name: Login to DockerHub
63+
uses: docker/login-action@v1
64+
with:
65+
username: ${{ secrets.DOCKERHUB_USERNAME }}
66+
password: ${{ secrets.DOCKERHUB_TOKEN }}
67+
68+
- name: Login to Quay
69+
uses: docker/login-action@v1
70+
with:
71+
registry: quay.io
72+
username: ${{ secrets.QUAY_USERNAME }}
73+
password: ${{ secrets.QUAY_TOKEN }}
74+
75+
- name: Build and push
76+
uses: docker/build-push-action@v2
77+
with:
78+
context: .
79+
file: ./${{ matrix.Dockerfile }}
80+
platforms: linux/amd64,linux/arm64
81+
push: ${{ github.event_name != 'pull_request' }}
82+
tags: ${{ steps.docker_meta.outputs.tags }}
83+
labels: ${{ steps.docker_meta.outputs.labels }}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: "Scheduled: docker"
2+
3+
on:
4+
schedule:
5+
- cron: '0 6 * * 1'
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Set Swap Space
14+
uses: pierotofy/set-swap-space@master
15+
with:
16+
swap-size-gb: 12
17+
18+
- name: Run Golangci lint
19+
uses: golangci/golangci-lint-action@v2
20+
with:
21+
version: latest
22+
args: --print-resources-usage
23+
24+
build:
25+
needs: lint
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
Dockerfile: [Dockerfile]
30+
suffix: [""]
31+
latest: ["auto"]
32+
include: []
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v2
36+
37+
- name: Set Swap Space
38+
uses: pierotofy/set-swap-space@master
39+
with:
40+
swap-size-gb: 12
41+
42+
- name: Docker meta
43+
id: docker_meta
44+
uses: docker/metadata-action@v4
45+
with:
46+
images: ${{ github.repository }},quay.io/${{ github.repository }}
47+
labels: |
48+
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/${{ github.repository }}/${{ github.event.repository.default_branch }}/README.md
49+
flavor: |
50+
latest=${{ matrix.latest }}
51+
suffix=${{ matrix.suffix }}
52+
53+
- name: Set up QEMU
54+
uses: docker/setup-qemu-action@v1
55+
56+
- name: Set up Docker Buildx
57+
uses: docker/setup-buildx-action@v1
58+
59+
- name: Login to DockerHub
60+
uses: docker/login-action@v1
61+
with:
62+
username: ${{ secrets.DOCKERHUB_USERNAME }}
63+
password: ${{ secrets.DOCKERHUB_TOKEN }}
64+
65+
- name: Login to Quay
66+
uses: docker/login-action@v1
67+
with:
68+
registry: quay.io
69+
username: ${{ secrets.QUAY_USERNAME }}
70+
password: ${{ secrets.QUAY_TOKEN }}
71+
72+
- name: Build and push
73+
uses: docker/build-push-action@v2
74+
with:
75+
context: .
76+
file: ./${{ matrix.Dockerfile }}
77+
platforms: linux/amd64,linux/arm64
78+
push: ${{ github.event_name != 'pull_request' }}
79+
tags: ${{ steps.docker_meta.outputs.tags }}
80+
labels: ${{ steps.docker_meta.outputs.labels }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
/goreplace
44
/go-replace
55
/build/
6+
/vendor/
67
/.idea
8+
/release-assets

.golangci.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
run:
2+
timeout: 120m
3+
4+
linters:
5+
enable:
6+
- asciicheck
7+
- bidichk
8+
- bodyclose
9+
- errorlint
10+
- exportloopref
11+
- gofmt
12+
- goimports
13+
- gosec
14+
15+
linters-settings:
16+
gosec:
17+
excludes: []
18+
confidence: low
19+
config:
20+
global:
21+
audit: true
22+
23+
issues: {}
24+
25+
output:
26+
sort-results: true

Dockerfile

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
1-
FROM golang:alpine AS buildenv
1+
#############################################
2+
# Build
3+
#############################################
4+
FROM --platform=$BUILDPLATFORM golang:1.19-alpine as build
25

3-
COPY . /go/src/go-replace
4-
WORKDIR /go/src/go-replace
6+
RUN apk upgrade --no-cache --force
7+
RUN apk add --update build-base make git
58

6-
RUN apk --no-cache add git \
7-
&& go get \
8-
&& go build \
9-
&& chmod +x go-replace \
10-
&& ./go-replace --version
9+
WORKDIR /go/src/github.com/webdevops/go-replace
1110

11+
# Dependencies
12+
COPY go.mod go.sum .
13+
RUN go mod download
14+
15+
# Compile
16+
COPY . .
17+
RUN make test
18+
ARG TARGETOS TARGETARCH
19+
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build
20+
21+
#############################################
22+
# Test
23+
#############################################
24+
FROM gcr.io/distroless/static as test
25+
USER 0:0
26+
WORKDIR /app
27+
COPY --from=build /go/src/github.com/webdevops/go-replace/go-replace .
28+
RUN ["./go-replace", "--help"]
29+
30+
#############################################
31+
# Final
32+
#############################################
1233
FROM alpine
13-
COPY --from=buildenv /go/src/go-replace/go-replace /usr/local/bin
14-
CMD ["go-replace"]
34+
ENV LOG_JSON=1
35+
WORKDIR /
36+
COPY --from=test /app /usr/local/bin
37+
USER 1000:1000
38+
ENTRYPOINT ["go-replace"]

0 commit comments

Comments
 (0)