From 9c6030bd1c992382467dba5e070077ea27e178d4 Mon Sep 17 00:00:00 2001 From: Sridhar Vemula Date: Wed, 8 Jul 2020 12:00:58 -0700 Subject: [PATCH] using goreleaser for semver builds on sloop. (#121) * using goreleaser for semver builds on sloop. Integrated with travis ci and docker. * fix: deploy script update to ignore new lines * fix: deploy script update to ignore new lines * fix: using make target instead of shell script as travis having issues with new lines * fix: removed travis environment variable from makefile * fix: updated build script --- .gitignore | 1 + .goreleaser.yml | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ .travis.yml | 8 +++++--- Dockerfile | 22 +++++++-------------- Makefile | 22 ++++++++++++++++----- 5 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 .goreleaser.yml diff --git a/.gitignore b/.gitignore index 76410e9..b8177ca 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /data/ coverage.out sloop.iml +dist \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..0204eb5 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,52 @@ +project_name: sloop +builds: + - id: sloop + main: ./pkg/sloop/main.go + binary: sloop + ldflags: + - -s -installsuffix=cgo + goos: + - linux + - darwin + - windows + goarch: + - amd64 +archives: + - id: sloop + builds: + - sloop + files: + - ./pkg/sloop/webfiles/**/* +dockers: + - goos: linux + goarch: amd64 + builds: + - sloop + binaries: + - sloop + extra_files: + - pkg/sloop/webfiles + image_templates: + - "salesforce/sloop:latest" + - "salesforce/sloop:{{ .Tag }}" + dockerfile: Dockerfile + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.name={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: desc + filters: + exclude: + - typo + - fix + - '^docs:' + - '^test:' + - Merge pull request + - Merge branch diff --git a/.travis.yml b/.travis.yml index b430105..ccd053c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,10 +10,12 @@ script: - make before_deploy: - - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + - test -n "$TRAVIS_TAG" && echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin deploy: provider: script - script: make docker-push + skip_cleanup: true + script: + - make release on: - branch: master \ No newline at end of file + tags: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0edf880..9a99ccd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,12 @@ -FROM golang:1.13 AS build - -WORKDIR /sloop -COPY go.mod go.sum ./ - -RUN go mod download - -COPY pkg ./pkg - -RUN curl -o /sloop/aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/aws-iam-authenticator \ +FROM alpine as build +RUN apk add --no-cache curl +RUN curl -o /aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/aws-iam-authenticator \ && wait \ - && chmod +x /sloop/aws-iam-authenticator -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s" -installsuffix cgo -o sloop ./pkg/sloop + && chmod +x /aws-iam-authenticator FROM gcr.io/distroless/base -COPY --from=build /sloop/sloop /sloop -COPY --from=build /sloop/pkg/sloop/webfiles /pkg/sloop/webfiles -COPY --from=build /sloop/aws-iam-authenticator /aws-iam-authenticator +COPY sloop /sloop +COPY pkg/sloop/webfiles /pkg/sloop/webfiles +COPY --from=build /aws-iam-authenticator /aws-iam-authenticator ENV PATH="/:${PATH}" CMD ["/sloop"] diff --git a/Makefile b/Makefile index 5ef6fe8..be0d6a9 100644 --- a/Makefile +++ b/Makefile @@ -13,12 +13,16 @@ run: linux: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install -ldflags "-s" -installsuffix cgo -v ./pkg/... -docker: - docker build . -t sloop +goreleaser: + @if [ ! -f "$(GOPATH)/bin/goreleaser" ];then \ + curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh -s -- -b "$(GOPATH)/bin/"; \ + fi -docker-push: docker - docker tag sloop:latest sloopimage/sloop:latest - docker push sloopimage/sloop:latest +docker-snapshot: goreleaser + $(GOPATH)/bin/goreleaser release --snapshot --rm-dist + +docker: goreleaser + $(GOPATH)/bin/goreleaser release --rm-dist --skip-publish generate: go generate ./pkg/... @@ -35,3 +39,11 @@ protobuf: cover: go test ./pkg/... -coverprofile=coverage.out go tool cover -html=coverage.out + +release: + @if [ ! -z "$(GITHUB_TOKEN)" ];then \ + curl -sfL https://git.io/goreleaser | sh -s -- release --rm-dist;\ + else \ + curl -sfL https://git.io/goreleaser | sh -s -- release --rm-dist --skip-publish && \ + docker push salesforce/sloop;\ + fi \ No newline at end of file