Skip to content

Commit

Permalink
CI: lint, build (bin and container) (#8)
Browse files Browse the repository at this point in the history
* fix: error printing

Signed-off-by: Pierre Ugaz <[email protected]>

* chore(ci): lint

Signed-off-by: Pierre Ugaz <[email protected]>

* chore(ci): install linter

Signed-off-by: Pierre Ugaz <[email protected]>

* chore(ci): build docker

Signed-off-by: Pierre Ugaz <[email protected]>

* chore: deps

Signed-off-by: Pierre Ugaz <[email protected]>

* chore: build

Signed-off-by: Pierre Ugaz <[email protected]>

* chore(ci): rename build

Signed-off-by: Pierre Ugaz <[email protected]>

* chore: add deps

Signed-off-by: Pierre Ugaz <[email protected]>

* chore(ci): add make

Signed-off-by: Pierre Ugaz <[email protected]>
  • Loading branch information
Pierre Ugaz authored Aug 24, 2020
1 parent 45857ed commit 23cbc37
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
56 changes: 56 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 1,56 @@
stages:
- lint
- test
- build
- release

lint:
image: golang:1.15.0-alpine3.12
stage: lint
before_script:
- apk add --no-cache make bash git gcc musl-dev file curl wget ca-certificates
- wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.30.0
- install ./bin/golangci-lint /bin/golangci-lint
- rm -f ./bin/golangci-lint
script:
- golangci-lint run -v

build:bin:
image: golang:1.15.0-alpine3.12
stage: build
before_script:
- apk add --no-cache make bash git gcc musl-dev file curl wget ca-certificates
script:
- make build
artifacts:
paths:
- build/deliver

.container:
image: docker:stable
stage: build
services:
- docker:stable-dind
before_script:
- apk add --no-cache make
- echo ${DOCKER_PASSWORD:-$CI_REGISTRY_PASSWORD}|docker login -u=${DOCKER_USER:-$CI_REGISTRY_USER} --password-stdin ${DOCKER_REGISTRY:-$CI_REGISTRY}
script:
- make build-docker
- make push-docker
after_script:
- docker logout

# build container image and upload it to gitlab registry
build:docker:
extends: .container
except:
- tags

# build container image and upload it to docker hub
release:docker:
extends: .container
stage: release
variables:
DOCKER_REGISTRY: docker.io
only:
- tags
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 1,22 @@
VERSION=$(CI_COMMIT_REF_NAME)-$(CI_COMMIT_SHORT_SHA)
CONTAINER_IMAGE=$(CI_REGISTRY_IMAGE)
ifdef CI_COMMIT_TAG
CONTAINER_IMAGE=docker.io/ulm0/deliver
VERSION=$(shell ./hack/version)
endif
LD_FLAGS=-s -w -extldflags -static -X github.com/ulm0/deliver/pkg/cli.Version=$(VERSION)
CONTAINER_LIST=$(CONTAINER_IMAGE):$(VERSION)
ifdef CI_COMMIT_TAG
# cheap fix for multiple tags
CONTAINER_LIST =-t $(CONTAINER_IMAGE):latest
endif

build:
@CGO_ENABLED=0 go build -a -ldflags="$(LD_FLAGS)" -installsuffix cgo -o build/deliver github.com/ulm0/deliver/cmd/deliver

build-docker:
@docker build --build-arg VERSION=$(VERSION) -t ulm0/deliver:$(VERSION) .
@echo $(CONTAINER_LIST)
@docker build --build-arg VERSION=$(VERSION) -t $(CONTAINER_LIST) .

push-docker:
@docker push ulm0/deliver:$(VERSION)
@docker push $(CONTAINER_IMAGE)

0 comments on commit 23cbc37

Please sign in to comment.