From 2dcd1b058af332c23b8fd8499a828ce463040e63 Mon Sep 17 00:00:00 2001 From: hetjagani Date: Sat, 31 Jul 2021 08:37:46 -0700 Subject: [PATCH] ci: added goreleaser config and CI action workflow --- .github/workflows/goreleaser.yml | 31 +++++++++++++++++++++++ .goreleaser.yml | 43 ++++++++++++++++++++++++++++++++ server/Dockerfile.prod | 25 +++---------------- 3 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/goreleaser.yml create mode 100644 .goreleaser.yml diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 00000000..e266956c --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,31 @@ +name: Release CI +on: + push: + tags: + - '*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Use Go + uses: actions/setup-go@v2 + id: setup_go + with: + go-version: '1.16.2' + - name: Cache go-modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + - name: Login Docker Hub + run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u deshetti --password-stdin + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000..999e4c59 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,43 @@ +project_name: kavach + +builds: +- id: kavach-server + dir: server + binary: kavach-server + env: + - CGO_ENABLED=0 + - GO386=softfloat + goos: + - linux + - darwin + - windows + +archives: + - id: kavach-server + builds: + - kavach-server + name_template: "kavach-server_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + +dockers: +- dockerfile: server/Dockerfile.prod + image_templates: + - "factly/kavach-server:{{ .Tag }}" + use: docker + build_flag_templates: + - "--platform=linux/amd64" + +docker_manifests: + - + image_templates: + - "factly/kavach-server:{{ .Version }}" + +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/server/Dockerfile.prod b/server/Dockerfile.prod index 84ef18fd..3a44eb83 100644 --- a/server/Dockerfile.prod +++ b/server/Dockerfile.prod @@ -1,29 +1,10 @@ -FROM golang:1.13-alpine AS build_base - -RUN apk add --no-cache git - -# Set the Current Working Directory inside the container -WORKDIR /tmp/kavach-server - -# We want to populate the module cache based on the go.{mod,sum} files. -COPY go.mod . -COPY go.sum . - -RUN go mod download - -COPY . . - -# Unit tests -# RUN CGO_ENABLED=0 go test -v - -# Build the Go app -RUN go build -o ./out/kavach-server . - # Start fresh from a smaller image FROM alpine:3.9 RUN apk add ca-certificates -COPY --from=build_base /tmp/kavach-server/out/kavach-server /app/kavach-server +RUN apk add gcc musl-dev +WORKDIR /app +COPY kavach-server . # Run the binary program produced by `go install` ENTRYPOINT ["/app/kavach-server"]