-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
executable file
·85 lines (64 loc) · 1.97 KB
/
Dockerfile
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
FROM centos:7
ENV REFRESHED_AT 2017-12-19
ARG PROGRAM_NAME="unknown"
ARG BUILD_VERSION=0.0.0
ARG BUILD_ITERATION=0
# --- Install Effing Package Manger (FPM) -------------------------------------
# Install dependencies
RUN yum -y install \
gcc \
make \
rpm-build \
ruby-devel \
rubygems \
which
# Install FPM
RUN gem install --no-ri --no-rdoc fpm
# --- Install Go --------------------------------------------------------------
ENV GO_VERSION=1.9.2
# Install dependencies.
RUN yum -y install \
git \
tar \
wget
# Install "go".
RUN wget https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd64.tar.gz && \
tar -C /usr/local/ -xzf go${GO_VERSION}.linux-amd64.tar.gz
# --- Compile go program ------------------------------------------------------
ENV HOME="/root"
ENV GOPATH="${HOME}/gocode"
ENV PATH="${PATH}:/usr/local/go/bin:${GOPATH}/bin"
ENV GO_PACKAGE="github.com/docktermj/${PROGRAM_NAME}"
# Copy local files from the Git repository.
COPY . ${GOPATH}/src/${GO_PACKAGE}
# Install dependencies.
WORKDIR ${GOPATH}/src/${GO_PACKAGE}
RUN go get -u github.com/golang/dep/cmd/dep
RUN dep ensure
# Build go program.
RUN go install \
-ldflags "-X main.programName=${PROGRAM_NAME} -X main.buildVersion=${BUILD_VERSION} -X main.buildIteration=${BUILD_ITERATION}" \
${GO_PACKAGE}
# Copy binary to output.
RUN mkdir -p /output/bin && \
cp /root/gocode/bin/${PROGRAM_NAME} /output/bin
# --- Package as RPM and DEB --------------------------------------------------
WORKDIR /output
# RPM package.
RUN fpm \
--input-type dir \
--output-type rpm \
--name ${PROGRAM_NAME} \
--version ${BUILD_VERSION} \
--iteration ${BUILD_ITERATION} \
/root/gocode/bin/=/usr/bin
# DEB package.
RUN fpm \
--input-type dir \
--output-type deb \
--name ${PROGRAM_NAME} \
--version ${BUILD_VERSION} \
--iteration ${BUILD_ITERATION} \
/root/gocode/bin/=/usr/bin
# --- Epilog ------------------------------------------------------------------
CMD ["/bin/bash"]