Skip to content

Commit 3ceaf01

Browse files
committed
feat: add goreleaser and github actions
1 parent d984cdc commit 3ceaf01

File tree

7 files changed

+271
-6
lines changed

7 files changed

+271
-6
lines changed

.github/workflows/goreleaser.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
name: publish github release artifacts with goreleaser
3+
on:
4+
push:
5+
tags: '*'
6+
jobs:
7+
goreleaser:
8+
runs-on: ubuntu-latest
9+
environment: release
10+
steps:
11+
- name: setup-go
12+
uses: actions/setup-go@v3
13+
with:
14+
go-version: '1.20'
15+
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up QEMU
22+
uses: docker/setup-qemu-action@v2
23+
24+
- name: Set up Docker Buildx
25+
id: buildx
26+
uses: docker/setup-buildx-action@v2
27+
28+
- name: Log in to the GitHub Container registry
29+
uses: docker/login-action@v2
30+
with:
31+
registry: ghcr.io
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Log in to the Docker Hub
36+
uses: docker/login-action@v2
37+
with:
38+
username: ${{ secrets.DOCKERHUB_USERNAME }}
39+
password: ${{ secrets.DOCKERHUB_TOKEN }}
40+
41+
- uses: actions/cache@v3
42+
with:
43+
path: |
44+
~/.cache/go-build
45+
~/go/pkg/mod
46+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
47+
restore-keys: |
48+
${{ runner.os }}-go-
49+
- if: steps.cache.outputs.cache-hit != 'true'
50+
run: go mod download
51+
52+
- name: goreleaser
53+
uses: goreleaser/goreleaser-action@v4
54+
with:
55+
version: latest
56+
args: release --clean
57+
env:
58+
DOCKER_GITHUB_REPO: ghcr.io/${{ github.actor }}/${{ github.repository }}
59+
DOCKER_HUB_REPO: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/certjunkie
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Terraform Provider testing workflow.
2+
name: Tests
3+
4+
# This GitHub action runs your tests for each pull request and push.
5+
# Optionally, you can turn it on using a schedule for regular testing.
6+
on:
7+
pull_request:
8+
paths-ignore:
9+
- 'README.md'
10+
push:
11+
paths-ignore:
12+
- 'README.md'
13+
14+
# Testing only needs permissions to read the repository contents.
15+
permissions:
16+
contents: read
17+
18+
# Default values to simplify job configurations below.
19+
env:
20+
# Go language version to use for building. This value should also be updated
21+
# in the release workflow if changed.
22+
GO_VERSION: '1.20'
23+
24+
jobs:
25+
# Build and test
26+
test:
27+
name: Test golang
28+
runs-on: ubuntu-latest
29+
timeout-minutes: 5
30+
steps:
31+
- uses: actions/setup-go@v3
32+
with:
33+
go-version: ${{ env.GO_VERSION }}
34+
35+
- name: Checkout
36+
uses: actions/checkout@v3
37+
with:
38+
fetch-depth: 0
39+
40+
- uses: actions/cache@v3
41+
with:
42+
path: |
43+
~/.cache/go-build
44+
~/go/pkg/mod
45+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
46+
restore-keys: |
47+
${{ runner.os }}-go-
48+
- if: steps.cache.outputs.cache-hit != 'true'
49+
run: go mod download
50+
51+
- run: go build -v .
52+
- run: go test -v -cover ./...
53+
54+
55+
# test goreleaser build
56+
goreleaser-snapshot:
57+
name: Test goreleaser
58+
runs-on: ubuntu-latest
59+
needs:
60+
- test
61+
timeout-minutes: 10
62+
steps:
63+
- uses: actions/setup-go@v3
64+
with:
65+
go-version: ${{ env.GO_VERSION }}
66+
67+
- name: Checkout
68+
uses: actions/checkout@v3
69+
with:
70+
fetch-depth: 0
71+
72+
- uses: actions/cache@v3
73+
with:
74+
path: |
75+
~/.cache/go-build
76+
~/go/pkg/mod
77+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
78+
restore-keys: |
79+
${{ runner.os }}-go-
80+
- if: steps.cache.outputs.cache-hit != 'true'
81+
run: go mod download
82+
83+
- name: Set up QEMU
84+
uses: docker/setup-qemu-action@v2
85+
86+
- name: Set up Docker Buildx
87+
id: buildx
88+
uses: docker/setup-buildx-action@v2
89+
90+
- name: goreleaser
91+
uses: goreleaser/goreleaser-action@v4
92+
with:
93+
version: latest
94+
args: release --snapshot --clean
95+
env:
96+
DOCKER_GITHUB_REPO: local
97+
DOCKER_HUB_REPO: local

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
dist/
2+
certjunkie
3+
14
.idea/
25

36
# Binaries for programs and plugins

.goreleaser.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
env:
5+
- CGO_ENABLED=0
6+
- GOPROXY=https://proxy.golang.org
7+
project_name: certjunkie
8+
9+
builds:
10+
- id: builds
11+
goos:
12+
- linux
13+
goarch:
14+
- amd64
15+
- arm64
16+
17+
main: main.go
18+
19+
dockers:
20+
- image_templates:
21+
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-amd64"
22+
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-amd64"
23+
use: buildx
24+
dockerfile: Dockerfile.goreleaser
25+
build_flag_templates:
26+
- "--platform=linux/amd64"
27+
28+
- image_templates:
29+
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-arm64"
30+
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-arm64"
31+
use: buildx
32+
goarch: arm64
33+
dockerfile: Dockerfile.goreleaser
34+
build_flag_templates:
35+
- "--platform=linux/arm64"
36+
37+
docker_manifests:
38+
# docker hub
39+
- name_template: "{{ .Env.DOCKER_HUB_REPO }}:latest"
40+
image_templates:
41+
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-amd64"
42+
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-arm64"
43+
- name_template: "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}"
44+
image_templates:
45+
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-amd64"
46+
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-arm64"
47+
48+
# github container
49+
- name_template: "{{ .Env.DOCKER_GITHUB_REPO }}:latest"
50+
image_templates:
51+
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-amd64"
52+
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-arm64"
53+
- name_template: "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}"
54+
image_templates:
55+
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-amd64"
56+
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-arm64"
57+
58+
checksum:
59+
name_template: "checksums.txt"
60+
61+
changelog:
62+
sort: asc
63+
use: github
64+
filters:
65+
exclude:
66+
- '^docs:'
67+
- '^test:'
68+
- '^chore'
69+
- Merge pull request
70+
- Merge remote-tracking branch
71+
- Merge branch
72+
- go mod tidy
73+
groups:
74+
- title: 'New Features'
75+
regexp: "^.*feat[(\\w)]*:+.*$"
76+
order: 0
77+
- title: 'Bug fixes'
78+
regexp: "^.*fix[(\\w)]*:+.*$"
79+
order: 10
80+
- title: Other work
81+
order: 999
82+
release:
83+
# If you want to manually examine the release before its live, uncomment this line:
84+
# draft: true
85+
footer: |
86+
**Full Changelog**: https://github.com/project0/certjunkie/compare/{{ .PreviousTag }}...{{ .Tag }}

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ FROM scratch
1212
WORKDIR /root/
1313

1414
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
15-
COPY --from=builder /go/src/github.com/project0/certjunkie/certjunkie .
15+
COPY --from=builder /go/src/github.com/project0/certjunkie/certjunkie /certjunkie
1616

17-
ENTRYPOINT ["./certjunkie"]
17+
ENTRYPOINT ["/certjunkie"]
1818

1919
CMD [ "server" ]

Dockerfile.goreleaser

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM golang:1.20-alpine as builder
2+
3+
FROM scratch
4+
5+
WORKDIR /root/
6+
COPY --from=builder /etc/ssl/certs /etc/ssl/certs
7+
8+
COPY certjunkie /certjunkie
9+
ENTRYPOINT ["/certjunkie"]
10+
11+
CMD [ "server" ]

main.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"errors"
5+
"fmt"
56
stdlog "log"
67
"os"
78
"os/signal"
@@ -23,10 +24,17 @@ import (
2324
"github.com/urfave/cli/v2"
2425
)
2526

26-
const ACME_STAGING = "https://acme-staging-v02.api.letsencrypt.org/directory"
27-
const ACME = "https://acme-v02.api.letsencrypt.org/directory"
27+
var (
28+
version = "dev"
29+
commit = "none"
30+
date = "unknown"
31+
)
2832

29-
const envPrefix = "CJ"
33+
const (
34+
ACME_STAGING = "https://acme-staging-v02.api.letsencrypt.org/directory"
35+
ACME = "https://acme-v02.api.letsencrypt.org/directory"
36+
envPrefix = "CJ"
37+
)
3038

3139
var certStore *certstore.CertStore
3240

@@ -39,7 +47,7 @@ func flagSetHelperEnvKey(name string) []string {
3947
func main() {
4048

4149
app := cli.NewApp()
42-
app.HideVersion = true
50+
app.Version = fmt.Sprintf("%s %s %s", version, commit, date)
4351
app.Usage = "issue certificate with ACME as a REST"
4452

4553
app.Flags = []cli.Flag{

0 commit comments

Comments
 (0)