18313: make the arvbox build scripts look up the Go compiler version to
[arvados.git] / tools / arvbox / lib / arvbox / docker / Dockerfile.base
1 # syntax = docker/dockerfile:experimental
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 ARG BUILDTYPE
7
8 # We're using poor man's conditionals (see
9 # https://www.docker.com/blog/advanced-dockerfiles-faster-builds-and-smaller-images-using-buildkit-and-multistage-builds/)
10 # here to dtrt in the dev/test scenario and the demo scenario. In the dev/test
11 # scenario, we use the docker context (i.e. the copy of Arvados checked out on
12 # the host) to build arvados-server. In the demo scenario, we check out a new
13 # tree, and use the $arvados_version commit (passed in via an argument).
14
15 ###########################################################################################################
16 FROM debian:10-slim as dev
17 ENV DEBIAN_FRONTEND noninteractive
18
19 RUN apt-get update && \
20     apt-get -yq --no-install-recommends -o Acquire::Retries=6 install \
21     build-essential ca-certificates git libpam0g-dev wget
22
23 ENV GOPATH /var/lib/gopath
24
25 RUN --mount=type=bind,target=/usr/src/arvados \
26     cd /usr/src/arvados && \
27     grep 'goversion :=' lib/install/deps.go |awk -F'"' '{print $2}'
28
29 ARG go_version
30
31 # Get Go
32 RUN cd /usr/src && \
33     wget https://golang.org/dl/go${go_version}.linux-amd64.tar.gz && \
34     tar xzf go${go_version}.linux-amd64.tar.gz && \
35     ln -s /usr/src/go/bin/go /usr/local/bin/go-${go_version} && \
36     ln -s /usr/src/go/bin/gofmt /usr/local/bin/gofmt-${go_version} && \
37     ln -s /usr/local/bin/go-${go_version} /usr/local/bin/go && \
38     ln -s /usr/local/bin/gofmt-${go_version} /usr/local/bin/gofmt
39
40 # the --mount option requires the experimental syntax enabled (enables
41 # buildkit) on the first line of this file. This Dockerfile must also be built
42 # with the DOCKER_BUILDKIT=1 environment variable set.
43 RUN --mount=type=bind,target=/usr/src/arvados \
44     cd /usr/src/arvados && \
45     go mod download && \
46     cd cmd/arvados-server && \
47     go install
48
49 ###########################################################################################################
50 FROM debian:10-slim as demo
51 ENV DEBIAN_FRONTEND noninteractive
52
53 RUN apt-get update && \
54     apt-get -yq --no-install-recommends -o Acquire::Retries=6 install \
55     build-essential ca-certificates git libpam0g-dev wget
56
57 ENV GOPATH /var/lib/gopath
58 ARG go_version
59
60 RUN cd /usr/src && \
61     wget https://golang.org/dl/go${go_version}.linux-amd64.tar.gz && \
62     tar xzf go${go_version}.linux-amd64.tar.gz && \
63     ln -s /usr/src/go/bin/go /usr/local/bin/go-${go_version} && \
64     ln -s /usr/src/go/bin/gofmt /usr/local/bin/gofmt-${go_version} && \
65     ln -s /usr/local/bin/go-${go_version} /usr/local/bin/go && \
66     ln -s /usr/local/bin/gofmt-${go_version} /usr/local/bin/gofmt
67
68 ARG arvados_version
69 RUN echo arvados_version is git commit $arvados_version
70
71 RUN cd /usr/src && \
72     git clone --no-checkout https://git.arvados.org/arvados.git && \
73     git -C arvados checkout ${arvados_version} && \
74     cd /usr/src/arvados && \
75     go mod download && \
76     cd cmd/arvados-server && \
77     go install
78
79 ###########################################################################################################
80 FROM ${BUILDTYPE} as base
81
82 ###########################################################################################################
83 FROM debian:10
84 ENV DEBIAN_FRONTEND noninteractive
85
86 # The arvbox-specific dependencies are
87 #  gnupg2 runit python3-pip python3-setuptools python3-yaml shellinabox netcat less
88 RUN apt-get update && \
89     apt-get -yq --no-install-recommends -o Acquire::Retries=6 install \
90     gnupg2 runit python3-pip python3-setuptools python3-yaml shellinabox netcat less vim-tiny && \
91     apt-get clean
92
93 ENV GOPATH /var/lib/gopath
94 RUN echo buildtype is $BUILDTYPE
95
96 RUN mkdir -p $GOPATH/bin/
97 COPY --from=base $GOPATH/bin/arvados-server $GOPATH/bin/arvados-server
98 RUN $GOPATH/bin/arvados-server --version
99 RUN $GOPATH/bin/arvados-server install -type test
100
101 RUN /etc/init.d/postgresql start && \
102     su postgres -c 'dropuser arvados' && \
103     su postgres -c 'createuser -s arvbox' && \
104     /etc/init.d/postgresql stop
105
106 ENV GEM_HOME /var/lib/arvados/lib/ruby/gems/2.5.0
107 ENV PATH $PATH:$GEM_HOME/bin
108
109 VOLUME /var/lib/docker
110 VOLUME /var/log/nginx
111 VOLUME /etc/ssl/private
112
113 ARG workdir
114
115 ADD $workdir/8D81803C0EBFCD88.asc /tmp/
116 RUN apt-key add --no-tty /tmp/8D81803C0EBFCD88.asc && \
117     rm -f /tmp/8D81803C0EBFCD88.asc
118
119 RUN mkdir -p /etc/apt/sources.list.d && \
120     echo deb https://download.docker.com/linux/debian/ buster stable > /etc/apt/sources.list.d/docker.list && \
121     apt-get update && \
122     apt-get -yq --no-install-recommends install docker-ce=5:20.10.6~3-0~debian-buster && \
123     apt-get clean
124
125 # Set UTF-8 locale
126 RUN echo en_US.UTF-8 UTF-8 > /etc/locale.gen && locale-gen
127 ENV LANG en_US.UTF-8
128 ENV LANGUAGE en_US:en
129 ENV LC_ALL en_US.UTF-8
130
131 ARG arvados_version
132 RUN echo arvados_version is git commit $arvados_version
133
134 COPY $workdir/fuse.conf /etc/
135
136 COPY $workdir/gitolite.rc \
137     $workdir/keep-setup.sh $workdir/common.sh $workdir/createusers.sh \
138     $workdir/logger $workdir/runsu.sh $workdir/waitforpostgres.sh \
139     $workdir/yml_override.py $workdir/api-setup.sh \
140     $workdir/go-setup.sh $workdir/devenv.sh $workdir/cluster-config.sh $workdir/edit_users.py \
141     /usr/local/lib/arvbox/
142
143 COPY $workdir/runit /etc/runit
144
145 # arvbox mounts a docker volume at $ARVADOS_CONTAINER_PATH, make sure that that
146 # doesn't overlap with the directory where `arvados-server install -type test`
147 # put everything (/var/lib/arvados)
148 ENV ARVADOS_CONTAINER_PATH /var/lib/arvados-arvbox
149
150 RUN /bin/ln -s /var/lib/arvados/bin/ruby /usr/local/bin/
151
152 # Start the supervisor.
153 ENV SVDIR /etc/service
154 STOPSIGNAL SIGINT
155 CMD ["/etc/runit/2"]