Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply change from some fork, asset templating and CI/CD release #58

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
97 changes: 97 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: release

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
github_release:
name: Create Release
runs-on: ubuntu-latest
steps:
-
name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
-
name: Cache Go modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
-
name: Tests
run: |
cd ./src/etcdkeeper
go mod tidy
go test -v ./...
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: success() && startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Duplication with docker.yml workflow cause the previous automatic release don't trigger a release created event
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Cache Docker layers
uses: actions/cache@v2
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
-
name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
-
name: Login to docker registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and Push docker image
id: docker_build
uses: docker/[email protected]
with:
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: "type=local,dest=/tmp/.buildx-cache"
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
-
name: Clear
if: always()
run: |
rm -f ${HOME}/.docker/config.json
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ bin

# Package Files
*.war
*.ear
*.ear
dist/
36 changes: 36 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
project_name: etcdkeeper

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
ignore:
- goos: windows
goarch: arm64
dir: ./src/etcdkeeper
archives:
- replacements:
386: i386
amd64: x86_64
format: zip
name_template: "{{ .ProjectName }}-v{{ .Version }}-{{ .Os }}_{{ .Arch }}"
wrap_in_directory: true
files:
- LICENSE
- README.md
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-snapshot"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
32 changes: 16 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
FROM golang:1.12 as build
FROM golang:1.17-alpine3.14 as build

ENV GO111MODULE on
ENV GOPROXY "https://goproxy.io"
WORKDIR /app
ADD . /app
WORKDIR /app/src/etcdkeeper

WORKDIR /opt
RUN mkdir etcdkeeper
ADD . /opt/etcdkeeper
WORKDIR /opt/etcdkeeper/src/etcdkeeper
ENV CGO_ENABLED=0

RUN go mod download \
&& go build -o etcdkeeper.bin main.go
RUN go mod download
RUN go build -o ../../etcdkeeper -ldflags='-w -s' -a -tags netgo -installsuffix netgo main.go


FROM alpine:3.10
FROM alpine:3.14.1

ENV HOST="0.0.0.0"
ENV PORT="8080"

# RUN apk add --no-cache ca-certificates
RUN apk add --no-cache ca-certificates

RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
# Create a user 'etcdkeeper' member of group 'etcdkeeper'
RUN addgroup -S etcdkeeper && \
adduser -S -D -h /etcdkeeper -G etcdkeeper etcdkeeper

WORKDIR /opt/etcdkeeper
COPY --from=build /opt/etcdkeeper/src/etcdkeeper/etcdkeeper.bin .
ADD assets assets
COPY --from=build --chown=etcdkeeper:etcdkeeper /app/etcdkeeper .

EXPOSE ${PORT}
USER etcdkeeper

ENTRYPOINT ./etcdkeeper.bin -h $HOST -p $PORT
ENTRYPOINT ["./etcdkeeper"]
CMD "-h $HOST -p $PORT"
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: all

all:
docker image build -t etcdkeeper:1.0.0-snapshot .

lint:
cd src/etcdkeeper && golangci-lint run --new-from-rev=HEAD~

dev:
cd src/etcdkeeper && go run main.go -h localhost
Loading