Skip to content

Commit

Permalink
Merge pull request #14 from zhill/ci_updates
Browse files Browse the repository at this point in the history
Make build and release more configurable
  • Loading branch information
zhill authored Nov 18, 2019
2 parents cfd2378 + 86b9250 commit b2e00ab
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
63 changes: 31 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
---
version: 2.1
jobs:
build:
unit_test:
description: Run tests for formatting
docker:
Expand All @@ -14,7 +15,7 @@ jobs:
- run:
name: Unit tests with Go
command: make test
build:
build_image:
docker:
- image: circleci/golang:1
steps:
Expand Down Expand Up @@ -50,37 +51,37 @@ jobs:
- run:
name: Login
command: echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
- run: |
# This is the content of https://git.io/goreleaser on 11/17/2019
set -e
- run:
name: Goreleaser
command: |
# This is the content of https://git.io/goreleaser on 11/17/2019
set -e
TAR_FILE="/tmp/goreleaser.tar.gz"
RELEASES_URL="https://github.com/goreleaser/goreleaser/releases"
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
TAR_FILE="/tmp/goreleaser.tar.gz"
RELEASES_URL="https://github.com/goreleaser/goreleaser/releases"
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
last_version() {
curl -sL -o /dev/null -w %{url_effective} "$RELEASES_URL/latest" |
rev |
cut -f1 -d'/'|
rev
}
last_version() {
curl -sL -o /dev/null -w %{url_effective} "$RELEASES_URL/latest" |
rev |
cut -f1 -d'/'|
rev
}
download() {
test -z "$VERSION" && VERSION="$(last_version)"
test -z "$VERSION" && {
echo "Unable to get goreleaser version." >&2
exit 1
download() {
test -z "$VERSION" && VERSION="$(last_version)"
test -z "$VERSION" && {
echo "Unable to get goreleaser version." >&2
exit 1
}
rm -f "$TAR_FILE"
curl -s -L -o "$TAR_FILE" \
"$RELEASES_URL/download/$VERSION/goreleaser_$(uname -s)_$(uname -m).tar.gz"
}
rm -f "$TAR_FILE"
curl -s -L -o "$TAR_FILE" \
"$RELEASES_URL/download/$VERSION/goreleaser_$(uname -s)_$(uname -m).tar.gz"
}
download
tar -xf "$TAR_FILE" -C "$TMPDIR"
"${TMPDIR}/goreleaser" "$@"
#- run: curl -sL https://git.io/goreleaser | bash
download
tar -xf "$TAR_FILE" -C "$TMPDIR"
"${TMPDIR}/goreleaser" "$@"
workflows:
default:
Expand All @@ -89,26 +90,24 @@ workflows:
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(-.*)*/

- build:
- build_image:
requires:
- unit_test
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*(-.*)*/

- push_dev_image:
context: dockerhub
requires:
- build
- build_image
filters:
branches:
only:
- master
- release:
context: dockerhub
requires:
- build
- unit_test
filters:
branches:
ignore: /.*/
Expand Down
4 changes: 3 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ builds:
binary: anchore-adapter
env:
- CGO_ENABLED=0
goarch:
- amd64
archives:
- replacements:
darwin: Darwin
Expand All @@ -27,7 +29,7 @@ changelog:
- '^test:'
dockers:
- image_templates:
- "docker.io/anchore/harbor-scanner-adapter:{{ .Version }}"
- "{{.Env.REPOSITORY}}:{{ .Version }}"
goos: linux
goarch: amd64
binaries:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ LABEL "source"="https://github.com/anchore/harbor-scanner-adapter"

RUN apk update && apk add --no-cache curl bash ca-certificates && update-ca-certificates

COPY bin/anchore-adapter /app/anchore-adapter
COPY anchore-adapter /app/anchore-adapter

ENTRYPOINT ["/app/anchore-adapter"]
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
COMMIT = $(shell git rev-parse HEAD)
BINARY := anchore-adapter
IMAGE_TAG := dev
IMAGE := anchore/harbor-scanner-adapter:$(IMAGE_TAG)
IMAGE_TAG ?= dev
REPOSITORY ?= anchore/harbor-scanner-adapter
IMAGE ?= $(REPOSITORY):$(IMAGE_TAG)

build: $(BINARY)

$(BINARY):
GOOS=linux GO111MODULE=on CGO_ENABLED=0 go build -o bin/$(BINARY) cmd/anchore-adapter/main.go
GOOS=linux GO111MODULE=on CGO_ENABLED=0 go build -o $(BINARY) cmd/anchore-adapter/main.go

.PHONY: container
container: build
Expand All @@ -23,7 +24,7 @@ clean-all: clean-container clean-binary

.PHONY: clean-binary
clean-binary:
rm bin/$(BINARY)
rm $(BINARY)

.PHONY: clean-container
clean-container:
Expand Down

0 comments on commit b2e00ab

Please sign in to comment.