Skip to content

Commit

Permalink
Merge pull request #34 from Financial-Times/fix/UPPSF-666-update-dock…
Browse files Browse the repository at this point in the history
…er-image

UPPSF-666-update-docker-image
  • Loading branch information
RosenTodorov-ft committed Sep 2, 2019
2 parents d22dace + 87f9561 commit 38b5999
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ workflows:
jobs:
build:
docker:
- image: circleci/golang:1.10
- image: circleci/golang:1
working_directory: /go/src/github.com/Financial-Times/public-people-api
environment:
CIRCLE_TEST_REPORTS: /tmp/test-results
Expand Down
41 changes: 21 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
FROM golang:1.10-alpine
FROM golang:1

ENV PROJECT=public-people-api
COPY . /${PROJECT}-sources/

RUN apk --no-cache --virtual .build-dependencies add git curl \
&& ORG_PATH="github.com/Financial-Times" \
&& REPO_PATH="${ORG_PATH}/${PROJECT}" \
&& mkdir -p $GOPATH/src/${ORG_PATH} \
# Linking the project sources in the GOPATH folder
&& ln -s /${PROJECT}-sources $GOPATH/src/${REPO_PATH} \
&& cd $GOPATH/src/${REPO_PATH} \
&& BUILDINFO_PACKAGE="${ORG_PATH}/${PROJECT}/vendor/${ORG_PATH}/service-status-go/buildinfo." \
&& VERSION="version=$(git describe --tag --always 2> /dev/null)" \
ENV ORG_PATH="github.com/Financial-Times"
ENV SRC_FOLDER="${GOPATH}/src/${ORG_PATH}/${PROJECT}"
ENV BUILDINFO_PACKAGE="${ORG_PATH}/${PROJECT}/vendor/${ORG_PATH}/service-status-go/buildinfo."

COPY . ${SRC_FOLDER}
WORKDIR ${SRC_FOLDER}

# Install dependancies
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh \
&& $GOPATH/bin/dep ensure -vendor-only

# Build app
RUN VERSION="version=$(git describe --tag --always 2> /dev/null)" \
&& DATETIME="dateTime=$(date -u +%Y%m%d%H%M%S)" \
&& REPOSITORY="repository=$(git config --get remote.origin.url)" \
&& REVISION="revision=$(git rev-parse HEAD)" \
&& BUILDER="builder=$(go version)" \
&& LDFLAGS="-X '"${BUILDINFO_PACKAGE}$VERSION"' -X '"${BUILDINFO_PACKAGE}$DATETIME"' -X '"${BUILDINFO_PACKAGE}$REPOSITORY"' -X '"${BUILDINFO_PACKAGE}$REVISION"' -X '"${BUILDINFO_PACKAGE}$BUILDER"'" \
&& echo "Build flags: $LDFLAGS" \
&& echo "Fetching dependencies..." \
&& curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh \
&& $GOPATH/bin/dep ensure -vendor-only \
&& go build -ldflags="${LDFLAGS}" \
&& mv ${PROJECT} /${PROJECT} \
&& apk del .build-dependencies \
&& rm -rf $GOPATH /var/cache/apk/*
&& LDFLAGS="-s -w -X '"${BUILDINFO_PACKAGE}$VERSION"' -X '"${BUILDINFO_PACKAGE}$DATETIME"' -X '"${BUILDINFO_PACKAGE}$REPOSITORY"' -X '"${BUILDINFO_PACKAGE}$REVISION"' -X '"${BUILDINFO_PACKAGE}$BUILDER"'" \
&& CGO_ENABLED=0 go build -a -o /artifacts/${PROJECT} -ldflags="${LDFLAGS}" \
&& echo "Build flags: ${LDFLAGS}"

# Multi-stage build - copy certs and the binary into the image
FROM scratch
WORKDIR /
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=0 /artifacts/* /

CMD [ "/public-people-api" ]

0 comments on commit 38b5999

Please sign in to comment.