Skip to content

Commit

Permalink
feat: add goreleaser and github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
project0 committed Mar 6, 2023
1 parent d984cdc commit 3ceaf01
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 6 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: publish github release artifacts with goreleaser
on:
push:
tags: '*'
jobs:
goreleaser:
runs-on: ubuntu-latest
environment: release
steps:
- name: setup-go
uses: actions/setup-go@v3
with:
go-version: '1.20'

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the GitHub Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to the Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- if: steps.cache.outputs.cache-hit != 'true'
run: go mod download

- name: goreleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
DOCKER_GITHUB_REPO: ghcr.io/${{ github.actor }}/${{ github.repository }}
DOCKER_HUB_REPO: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/certjunkie
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97 changes: 97 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Terraform Provider testing workflow.
name: Tests

# This GitHub action runs your tests for each pull request and push.
# Optionally, you can turn it on using a schedule for regular testing.
on:
pull_request:
paths-ignore:
- 'README.md'
push:
paths-ignore:
- 'README.md'

# Testing only needs permissions to read the repository contents.
permissions:
contents: read

# Default values to simplify job configurations below.
env:
# Go language version to use for building. This value should also be updated
# in the release workflow if changed.
GO_VERSION: '1.20'

jobs:
# Build and test
test:
name: Test golang
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- if: steps.cache.outputs.cache-hit != 'true'
run: go mod download

- run: go build -v .
- run: go test -v -cover ./...


# test goreleaser build
goreleaser-snapshot:
name: Test goreleaser
runs-on: ubuntu-latest
needs:
- test
timeout-minutes: 10
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- if: steps.cache.outputs.cache-hit != 'true'
run: go mod download

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: goreleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --snapshot --clean
env:
DOCKER_GITHUB_REPO: local
DOCKER_HUB_REPO: local
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
dist/
certjunkie

.idea/

# Binaries for programs and plugins
Expand Down
86 changes: 86 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
before:
hooks:
- go mod download
env:
- CGO_ENABLED=0
- GOPROXY=https://proxy.golang.org
project_name: certjunkie

builds:
- id: builds
goos:
- linux
goarch:
- amd64
- arm64

main: main.go

dockers:
- image_templates:
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-amd64"
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-amd64"
use: buildx
dockerfile: Dockerfile.goreleaser
build_flag_templates:
- "--platform=linux/amd64"

- image_templates:
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-arm64"
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-arm64"
use: buildx
goarch: arm64
dockerfile: Dockerfile.goreleaser
build_flag_templates:
- "--platform=linux/arm64"

docker_manifests:
# docker hub
- name_template: "{{ .Env.DOCKER_HUB_REPO }}:latest"
image_templates:
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-amd64"
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-arm64"
- name_template: "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}"
image_templates:
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-amd64"
- "{{ .Env.DOCKER_HUB_REPO }}:{{ .Version }}-arm64"

# github container
- name_template: "{{ .Env.DOCKER_GITHUB_REPO }}:latest"
image_templates:
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-amd64"
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-arm64"
- name_template: "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}"
image_templates:
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-amd64"
- "{{ .Env.DOCKER_GITHUB_REPO }}:{{ .Version }}-arm64"

checksum:
name_template: "checksums.txt"

changelog:
sort: asc
use: github
filters:
exclude:
- '^docs:'
- '^test:'
- '^chore'
- Merge pull request
- Merge remote-tracking branch
- Merge branch
- go mod tidy
groups:
- title: 'New Features'
regexp: "^.*feat[(\\w)]*:+.*$"
order: 0
- title: 'Bug fixes'
regexp: "^.*fix[(\\w)]*:+.*$"
order: 10
- title: Other work
order: 999
release:
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
footer: |
**Full Changelog**: https://github.com/project0/certjunkie/compare/{{ .PreviousTag }}...{{ .Tag }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ FROM scratch
WORKDIR /root/

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

ENTRYPOINT ["./certjunkie"]
ENTRYPOINT ["/certjunkie"]

CMD [ "server" ]
11 changes: 11 additions & 0 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.20-alpine as builder

FROM scratch

WORKDIR /root/
COPY --from=builder /etc/ssl/certs /etc/ssl/certs

COPY certjunkie /certjunkie
ENTRYPOINT ["/certjunkie"]

CMD [ "server" ]
16 changes: 12 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"errors"
"fmt"
stdlog "log"
"os"
"os/signal"
Expand All @@ -23,10 +24,17 @@ import (
"github.com/urfave/cli/v2"
)

const ACME_STAGING = "https://acme-staging-v02.api.letsencrypt.org/directory"
const ACME = "https://acme-v02.api.letsencrypt.org/directory"
var (
version = "dev"
commit = "none"
date = "unknown"
)

const envPrefix = "CJ"
const (
ACME_STAGING = "https://acme-staging-v02.api.letsencrypt.org/directory"
ACME = "https://acme-v02.api.letsencrypt.org/directory"
envPrefix = "CJ"
)

var certStore *certstore.CertStore

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

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

app.Flags = []cli.Flag{
Expand Down

0 comments on commit 3ceaf01

Please sign in to comment.