# This Dockerfile makes the "build box": the container used to build official
# releases of Teleport and its documentation.
FROM centos:6

ARG UID
ARG GID
ARG GO_BOOTSTRAP_RUNTIME=go1.9.7

ENV LANGUAGE=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
ENV LC_CTYPE=en_US.UTF-8

COPY pam/pam_teleport.so /lib/x86_64-linux-gnu/security
COPY pam/teleport-acct-failure /etc/pam.d
COPY pam/teleport-session-failure /etc/pam.d
COPY pam/teleport-success /etc/pam.d

RUN yum makecache fast && yum -y install gcc pam-devel glibc-devel net-tools tree git zip && yum clean all

RUN (groupadd jenkins --gid=$GID -o && useradd jenkins --uid=$UID --gid=$GID --create-home --shell=/bin/sh ;\
     mkdir -p /var/lib/teleport && chown -R jenkins /var/lib/teleport)

# Install etcd.
RUN (curl -L https://github.com/coreos/etcd/releases/download/v3.3.9/etcd-v3.3.9-linux-amd64.tar.gz | tar -xz ;\
     cp etcd-v3.3.9-linux-amd64/etcd* /bin/)

# 1) Install binary go runtime for bootstrapping
# 2) Get source for the correct Go boringcrypto runtime and compile it with Go bootstrap runtime
# 3) Erase Go bootstrap runtime and create build directories
# 4) Print compiled Go version
ARG RUNTIME
RUN mkdir -p /go-bootstrap && cd /go-bootstrap && curl https://dl.google.com/go/${GO_BOOTSTRAP_RUNTIME}.linux-amd64.tar.gz | tar xz && \
    mkdir -p /opt && cd /opt && curl https://dl.google.com/go/${RUNTIME}.src.tar.gz | tar xz && \
    cd /opt/go/src && GOROOT_BOOTSTRAP=/go-bootstrap/go ./make.bash && \
    rm -rf /go-bootstrap && \
    mkdir -p /gopath/src/github.com/gravitational/teleport && \
    chmod a+w /gopath && \
    chmod a+w /var/lib && \
    chmod a-w / && \
    /opt/go/bin/go version

ENV GOPATH="/gopath" \
    GOROOT="/opt/go" \
    PATH="$PATH:/opt/go/bin:/gopath/bin:/gopath/src/github.com/gravitational/teleport/build"

VOLUME ["/gopath/src/github.com/gravitational/teleport"]
EXPOSE 6600 2379 2380
