Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update docker automation #152

Merged
merged 7 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.13.x
- 1.14.x
- tip

os:
Expand All @@ -19,6 +19,9 @@ script:
- make style codecov

jobs:
fast_finish: true
allow_failures:
- go: tip
include:
# - stage: integration
# name: "Integration Tests"
Expand Down Expand Up @@ -52,4 +55,14 @@ jobs:
api_key: "$GH_TOKEN"
file_glob: true
file: ./.ignore/*
skip_cleanup: true
skip_cleanup: true
- stage: docker-release
name: "Make Docker Release"
if: branch != master
script: skip
deploy:
- provider: script
script: bash deploy/docker_push
on:
all_branches: true
tags: true
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
- add optional config for tr1d1um to use its own authentication tokens (basic and jwt supported) [#148](https://github.com/xmidt-org/tr1d1um/pull/148)
- remove mention of XPC team in error message [#150](https://github.com/xmidt-org/tr1d1um/pull/150)
- bump golang version [#152](https://github.com/xmidt-org/tr1d1um/pull/152)
- use scratch as docker base image instead of alpine [#152](https://github.com/xmidt-org/tr1d1um/pull/152)
- add docker automation [#152](https://github.com/xmidt-org/tr1d1um/pull/152)

## [v0.4.0]
- fix a bug in which tr1d1um was returning 500 for user error requests [#146](https://github.com/xmidt-org/tr1d1um/pull/146)
Expand Down
16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ DOCKER_ORG := xmidt
PROGVER = $(shell git describe --tags `git rev-list --tags --max-count=1` | tail -1 | sed 's/v\(.*\)/\1/')
BUILDTIME = $(shell date -u '+%Y-%m-%d %H:%M:%S')
GITCOMMIT = $(shell git rev-parse --short HEAD)
GOFLAGS = -a -installsuffix cgo -ldflags "-w -s -X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(PROGVER)" -o $(APP)

.PHONY: go-mod-vendor
go-mod-vendor:
GO111MODULE=on $(GO) mod vendor

.PHONY: build
build: go-mod-vendor
$(GO) build -o $(APP) -ldflags "-X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(PROGVER)"
build:
CGO_ENABLED=0 $(GO) build $(GOFLAGS)

.PHONY: version
version:
Expand All @@ -36,11 +34,11 @@ update-version:


.PHONY: install
install: go-mod-vendor
install:
$(GO) install -ldflags "-X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(PROGVER)"

.PHONY: release-artifacts
release-artifacts: go-mod-vendor
release-artifacts:
mkdir -p ./.ignore
GOOS=darwin GOARCH=amd64 $(GO) build -o ./.ignore/$(APP)-$(PROGVER).darwin-amd64 -ldflags "-X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(PROGVER)"
GOOS=linux GOARCH=amd64 $(GO) build -o ./.ignore/$(APP)-$(PROGVER).linux-amd64 -ldflags "-X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(PROGVER)"
Expand All @@ -59,14 +57,14 @@ local-docker:
--build-arg VERSION=$(PROGVER)+local \
--build-arg GITCOMMIT=$(GITCOMMIT) \
--build-arg BUILDTIME='$(BUILDTIME)' \
-f ./deploy/Dockerfile.local -t $(DOCKER_ORG)/$(APP):local .
-f ./deploy/Dockerfile -t $(DOCKER_ORG)/$(APP):local .

.PHONY: style
style:
! $(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'

.PHONY: test
test: go-mod-vendor
test:
GO111MODULE=on $(GO) test -v -race -coverprofile=cover.out ./...

.PHONY: test-cover
Expand Down
41 changes: 26 additions & 15 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
FROM golang:alpine as builder
FROM docker.io/library/golang:1.14-alpine as builder

MAINTAINER Jack Murdock <jack_murdock@comcast.com>

WORKDIR /go/src/github.com/xmidt-org/tr1d1um

ARG VERSION=unknown
ARG GITCOMMIT=unknown
ARG BUILDTIME=unknown

RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh

RUN apk add --no-cache --no-progress \
ca-certificates \
make \
git \
openssh \
gcc \
libc-dev \
upx

COPY . .
RUN GO111MODULE=on go build \
-o tr1d1um_linux_amd64 \
-ldflags "-X 'main.BuildTime=${BUILDTIME}' -X main.GitCommit=${GITCOMMIT} -X main.Version=${VERSION}"
RUN make build

FROM scratch

FROM alpine
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/src/github.com/xmidt-org/tr1d1um/tr1d1um.yaml /tr1d1um.yaml
COPY --from=builder /go/src/github.com/xmidt-org/tr1d1um/tr1d1um /tr1d1um
COPY --from=builder /go/src/github.com/xmidt-org/tr1d1um/deploy/Dockerfile /go/src/github.com/xmidt-org/tr1d1um/NOTICE /go/src/github.com/xmidt-org/tr1d1um/LICENSE /go/src/github.com/xmidt-org/tr1d1um/CHANGELOG.md /

RUN apk --no-cache add ca-certificates
RUN mkdir -p /etc/tr1d1um
VOLUME /etc/tr1d1um
EXPOSE 6100
EXPOSE 6101
EXPOSE 6102
EXPOSE 6103

EXPOSE 8080
USER nobody
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this command? If so, maybe xmidt would be a better name and we keep it the same across all Makefiles


COPY --from=builder /go/src/github.com/xmidt-org/tr1d1um/tr1d1um_linux_amd64 /
COPY tr1d1um.yaml /
COPY deploy/Dockerfile NOTICE LICENSE CHANGELOG.md /
ENTRYPOINT ["/tr1d1um_linux_amd64"]
ENTRYPOINT ["/tr1d1um"]
28 changes: 0 additions & 28 deletions deploy/Dockerfile.local

This file was deleted.

16 changes: 16 additions & 0 deletions deploy/docker_push
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

# upload docker as $TRAVIS_TAG or latest
echo "$DOCKER_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin

LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1` | tail -1 | sed 's/v\(.*\)/\1/')
VERSION_TAG=$(echo "$TRAVIS_TAG" | sed 's/v\(.*\)/\1/')

docker build --build-arg VERSION="$VERSION_TAG" --build-arg GITCOMMIT="`git rev-parse --short HEAD`" --build-arg BUILDTIME="`date -u '+%Y-%m-%d %H:%M:%S'`" -f ./deploy/Dockerfile -t xmidt/tr1d1um:$VERSION_TAG .

docker push xmidt/tr1d1um:$VERSION_TAG

if [[ "$VERSION_TAG" == "$LATEST_TAG" ]]; then
docker tag xmidt/tr1d1um:$VERSION_TAG xmidt/tr1d1um:latest
docker push xmidt/tr1d1um:latest
fi
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/xmidt-org/tr1d1um

go 1.12
go 1.14

require (
github.com/aws/aws-sdk-go v1.23.11 // indirect
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ github.com/xmidt-org/webpa-common v1.7.0 h1:0FB/SQIePQigZ2DDMWSjRml2FxPLZJPrcq1s
github.com/xmidt-org/webpa-common v1.7.0/go.mod h1:PV4+42cjvL2hCj17Jb+Rnik9DszDG/DjHz8IT8e52ww=
github.com/xmidt-org/wrp-go v1.3.3 h1:WvODdrtxPwHEUqwfwHpu+kNUfBzLBfAIdrKCQjoCblc=
github.com/xmidt-org/wrp-go v1.3.3/go.mod h1:VOKYeeVWc2cyYmGWJksqUCV/lGzReRl0EP74y3mcWp0=
github.com/xmidt-org/wrp-go v1.3.4 h1:7kj+1VXRNNEI7G0Z3z7C58QpIXrWzTw/eI79FdAhyPA=
github.com/xmidt-org/wrp-go/v2 v2.0.0 h1:5qWc3uZDQNxjunUqK9HMrWZcdCaTtUVCtR+SSYWSK6I=
github.com/xmidt-org/wrp-go/v2 v2.0.0/go.mod h1:v0HK0go/7OSVDvKbnXsUn6c+M987p0yyxWEs8/Fmf60=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand Down