Skip to content

Commit

Permalink
Build static binary within docker
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas committed Nov 6, 2017
1 parent 6dd3761 commit 4d6d8bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
6 changes: 1 addition & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ jobs:
steps:
- checkout
- setup_remote_docker
- run: curl -L -s https://github.com/golang/dep/releases/download/v0.3.2/dep-linux-amd64 -o /go/bin/dep && chmod +x /go/bin/dep
- run: go get -u golang.org/x/tools/cmd/goimports
- run: dep ensure -vendor-only
- run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-s -X github.com/ory/oathkeeper/cmd.Version=`git describe --tags` -X github.com/ory/oathkeeper/cmd.BuildTime=`TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ'` -X github.com/ory/oathkeeper/cmd.GitHash=`git rev-parse HEAD`" -installsuffix cgo -o oathkeeper-docker-bin
- run: docker build -f Dockerfile -t oryd/oathkeeper:$CIRCLE_TAG .
- run: docker build --build-arg git_tag=$(git describe --tags) --build-arg git_commit=$(git rev-parse HEAD) -f Dockerfile -t oryd/oathkeeper:$CIRCLE_TAG .
- run: docker login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD"
- run: docker push oryd/oathkeeper:$CIRCLE_TAG

Expand Down
26 changes: 21 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
FROM alpine:3.6
FROM golang:1.9-alpine

RUN apk add --update ca-certificates # Certificates for SSL
ARG git_tag
ARG git_commit

ADD oathkeeper-docker-bin /go/bin/oathkeeper
RUN chmod a=+x /go/bin/oathkeeper
RUN apk add --no-cache git build-base curl
RUN curl -L -s https://github.com/golang/dep/releases/download/v0.3.2/dep-linux-amd64 -o $GOPATH/bin/dep
RUN chmod +x $GOPATH/bin/dep

ENTRYPOINT ["/go/bin/oathkeeper"]
WORKDIR /go/src/github.com/ory/oathkeeper

ADD ./Gopkg.lock ./Gopkg.lock
ADD ./Gopkg.toml ./Gopkg.toml
RUN dep ensure -vendor-only

ADD . .

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -X github.com/ory/oathkeeper/cmd.Version=$git_tag -X github.com/ory/oathkeeper/cmd.BuildTime=`TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ'` -X github.com/ory/oathkeeper/cmd.GitHash=$git_commit" -a -installsuffix cgo -o oathkeeper

FROM scratch

COPY --from=0 /go/src/github.com/ory/oathkeeper/oathkeeper /oathkeeper

ENTRYPOINT ["/oathkeeper"]

0 comments on commit 4d6d8bf

Please sign in to comment.