-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile.openshift
54 lines (43 loc) · 1.92 KB
/
Dockerfile.openshift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# build image
FROM centos:7
LABEL author="Xavier Coulon <[email protected]>"
ENV LANG=en_US.utf8
# Install wget and git
RUN yum --enablerepo=centosplus install -y \
wget \
git
# install golang 1.10.1
ENV GOLANG_VERSION=1.10.1
RUN wget -O /opt/go${GOLANG_VERSION}.linux-amd64.tar.gz https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz && \
tar -C /usr/local -xzf /opt/go${GOLANG_VERSION}.linux-amd64.tar.gz
ENV PATH=$PATH:/usr/local/go/bin
ENV GOPATH=/go
# install 'dep' for Go package management
RUN go get -u github.com/golang/dep/cmd/dep
# import source from host
ADD . /go/src/github.com/xcoulon/go-url-shortener
WORKDIR /go/src/github.com/xcoulon/go-url-shortener
RUN $GOPATH/bin/dep ensure -v
# run the tests, using build args to specify the connection settings to the Postgres DB
# optional args that can be filled with `build-arg` when executing the `docker build` command
#ARG POSTGRES_HOST
#ARG POSTGRES_PORT
#ARG POSTGRES_USER
#ARG POSTGRES_PASSWORD
#RUN LOG_LEVEL=debug go test ./...
# build the application
ARG BUILD_COMMIT=unknown
ARG BUILD_TIME=unknown
RUN go build -ldflags "-X github.com/xcoulon/go-url-shortener/configuration.BuildCommit=${BUILD_COMMIT} -X github.com/xcoulon/go-url-shortener/configuration.BuildTime=${BUILD_TIME}" -o bin/go-url-shortener
LABEL url-shortener.version=${BUILD_COMMIT} \
url-shortener.build-time=${BUILD_TIME}
# Add the binary file generated in the `builder` container above
RUN mv /go/src/github.com/xcoulon/go-url-shortener/bin/go-url-shortener /usr/local/bin/go-url-shortener
# Create a non-root user and a group with the same name: "shortenerapp"
ENV USER_GROUP=shortenerapp
RUN groupadd -r ${USER_GROUP} && \
useradd --no-create-home -g ${USER_GROUP} ${USER_GROUP}
# From here onwards, any RUN, CMD, or ENTRYPOINT will be run under the following user instead of 'root'
USER ${USER_GROUP}
EXPOSE 8080
ENTRYPOINT [ "/usr/local/bin/go-url-shortener" ]