-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Makefile and Dockerfile. Add a Jenkinsfile
Signed-off-by: Jean-Christophe Sirot <jean-christophe.sirot@docker.com>
- Loading branch information
Jean-Christophe Sirot
committed
Jun 12, 2019
1 parent
f0b63ad
commit 41561d1
Showing
7 changed files
with
235 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
properties([buildDiscarder(logRotator(numToKeepStr: '20'))]) | ||
|
||
pipeline { | ||
agent { | ||
label 'ubuntu-1804' | ||
} | ||
|
||
options { | ||
skipDefaultCheckout(true) | ||
} | ||
|
||
environment { | ||
TAG = tag() | ||
BUILD_TAG = tag() | ||
} | ||
|
||
stages { | ||
stage('Build') { | ||
parallel { | ||
stage("Validate") { | ||
agent { | ||
label 'ubuntu-1804' | ||
} | ||
steps { | ||
dir('src/github.com/docker/cnab-to-oci') { | ||
checkout scm | ||
ansiColor('xterm') { | ||
sh 'make -f docker.Makefile lint' | ||
} | ||
} | ||
} | ||
post { | ||
always { | ||
sh 'make -f docker.Makefile clean-images' | ||
deleteDir() | ||
} | ||
} | ||
} | ||
stage("Binaries") { | ||
agent { | ||
label 'ubuntu-1804' | ||
} | ||
steps { | ||
dir('src/github.com/docker/cnab-to-oci') { | ||
checkout scm | ||
ansiColor('xterm') { | ||
sh 'make -f docker.Makefile build test-unit' | ||
} | ||
dir('bin') { | ||
stash name: 'binaries' | ||
} | ||
} | ||
} | ||
post { | ||
always { | ||
sh 'make -f docker.Makefile clean-images' | ||
deleteDir() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
stage('Test') { | ||
agent { | ||
label 'ubuntu-1804' | ||
} | ||
steps { | ||
dir('src/github.com/docker/cnab-to-oci') { | ||
checkout scm | ||
ansiColor('xterm') { | ||
sh 'make -f docker.Makefile test-e2e' | ||
} | ||
} | ||
} | ||
post { | ||
always { | ||
sh 'make -f docker.Makefile clean-images' | ||
deleteDir() | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
include vars.mk | ||
|
||
LINT_IMAGE_NAME := $(BIN_NAME)-lint:$(TAG) | ||
DEV_IMAGE_NAME := $(BIN_NAME)-dev:$(TAG) | ||
E2E_IMAGE_NAME := $(BIN_NAME)-e2e:$(TAG) | ||
|
||
BIN_CTNR_NAME := $(BIN_NAME)-bin-$(TAG) | ||
|
||
.DEFAULT: all | ||
all: build test | ||
|
||
create_bin: | ||
@$(call mkdir,bin) | ||
|
||
build_dev_image: | ||
docker build $(BUILD_ARGS) --target=build -t $(DEV_IMAGE_NAME) . | ||
|
||
build_e2e_image: | ||
docker build $(BUILD_ARGS) --target=e2e -t $(E2E_IMAGE_NAME) . | ||
|
||
build: create_bin build_dev_image | ||
docker create --name $(BIN_CTNR_NAME) $(DEV_IMAGE_NAME) noop | ||
docker cp $(BIN_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-linux | ||
docker cp $(BIN_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-darwin | ||
docker cp $(BIN_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-windows.exe bin/$(BIN_NAME)-windows.exe | ||
docker rm $(BIN_CTNR_NAME) | ||
@$(call chmod,+x,bin/$(BIN_NAME)-linux) | ||
@$(call chmod,+x,bin/$(BIN_NAME)-darwin) | ||
@$(call chmod,+x,bin/$(BIN_NAME)-windows.exe) | ||
|
||
shell: build_dev_image ## run a shell in the docker build image | ||
docker run -ti --rm $(DEV_IMAGE_NAME) bash | ||
|
||
test: test-unit test-e2e ## run all tests | ||
|
||
test-unit: build_dev_image ## run unit tests | ||
docker run --rm $(DEV_IMAGE_NAME) make test-unit | ||
|
||
test-e2e: build_e2e_image ## run e2e tests | ||
docker run --rm -v /var/run:/var/run:ro --network="host" $(E2E_IMAGE_NAME) | ||
|
||
lint: ## run linter(s) | ||
$(info Linting...) | ||
docker build -t $(LINT_IMAGE_NAME) -f lint.Dockerfile . | ||
docker run --rm $(LINT_IMAGE_NAME) gometalinter --config=gometalinter.json ./... | ||
|
||
clean-images: ## Delete images | ||
docker image rm -f $(DEV_IMAGE_NAME) | ||
docker image rm -f $(E2E_IMAGE_NAME) | ||
docker image rm -f $(LINT_IMAGE_NAME) | ||
|
||
.PHONY: lint test-e2e test-unit test shell build gradle-test shell build_e2e_image build_dev_image create_bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ARG ALPINE_VERSION=3.8 | ||
ARG GO_VERSION=1.11.4 | ||
|
||
# base image | ||
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} as lint | ||
|
||
RUN apk add --no-cache \ | ||
curl \ | ||
git \ | ||
make \ | ||
coreutils | ||
RUN go get github.com/alecthomas/gometalinter && gometalinter --install | ||
|
||
WORKDIR /go/src/github.com/docker/cnab-to-oci | ||
ENV CGO_ENABLED=0 | ||
|
||
COPY . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
PKG_NAME := github.com/docker/cnab-to-oci | ||
PKG_PATH := /go/src/$(PKG_NAME) | ||
BIN_NAME ?= cnab-to-oci | ||
E2E_NAME := $(BIN_NAME)-e2e | ||
|
||
EXEC_EXT := | ||
ifeq ($(OS),Windows_NT) | ||
EXEC_EXT := .exe | ||
endif | ||
|
||
# Failing to resolve sh.exe to a full path denotes a windows vanilla shell. | ||
# Although 'simple' commands are still exec'ed, 'complex' ones are batch'ed instead of sh'ed. | ||
ifeq ($(SHELL),sh.exe) | ||
mkdir = mkdir $(subst /,\,$(1)) > nul 2>&1 || (exit 0) | ||
rm = del /F /Q $(subst /,\,$(1)) > nul 2>&1 || (exit 0) | ||
rmdir = rmdir /S /Q $(subst /,\,$(1)) > nul 2>&1 || (exit 0) | ||
chmod = | ||
BUILDTIME ?= unknown | ||
NULL := nul | ||
else | ||
# The no-op redirection forces make to shell out the commands instead of spawning a process as | ||
# the latter can fail on windows running cmd or powershell while having a unix style shell in the path. | ||
mkdir = mkdir -p $(1) 1>&1 | ||
rm = rm -rf $(1) 1>&1 | ||
rmdir = rm -rf $(1) 1>&1 | ||
chmod = chmod $(1) $(2) 1>&1 | ||
NULL := /dev/null | ||
endif | ||
|
||
ifeq ($(BUILD_TAG),) | ||
BUILD_TAG := $(shell git describe --always --dirty --abbrev=10 2> $(NULL)) | ||
endif | ||
ifeq ($(TAG),) | ||
ifeq ($(TAG_NAME),) | ||
TAG := $(BUILD_TAG) | ||
else | ||
TAG := $(TAG_NAME) | ||
endif | ||
endif | ||
ifeq ($(COMMIT),) | ||
COMMIT := $(shell git rev-parse --short HEAD 2> $(NULL)) | ||
endif | ||
|
||
ifeq ($(BUILDTIME),) | ||
BUILDTIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" 2> $(NULL)) | ||
endif | ||
ifeq ($(BUILDTIME),) | ||
BUILDTIME := unknown | ||
$(warning unable to set BUILDTIME. Set the value manually) | ||
endif | ||
|
||
LDFLAGS := "-s -w \ | ||
-X $(PKG_NAME)/internal.GitCommit=$(COMMIT) \ | ||
-X $(PKG_NAME)/internal.Version=$(TAG) \ | ||
-X $(PKG_NAME)/internal.BuildTime=$(BUILDTIME)" | ||
|
||
BUILD_ARGS := \ | ||
--build-arg BUILDTIME=$(BUILDTIME) \ | ||
--build-arg COMMIT=$(COMMIT) \ | ||
--build-arg TAG=$(TAG) | ||
|
||
GO_BUILD := CGO_ENABLED=0 go build -ldflags=$(LDFLAGS) | ||
GO_TEST := CGO_ENABLED=0 go test -ldflags=$(LDFLAGS) -failfast | ||
GO_TEST_RACE := go test -ldflags=$(LDFLAGS) -failfast -race |