21700: Install Bundler system-wide in Rails postinst
[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:11-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 ARG go_version
25
26 # Get Go
27 RUN cd /usr/src && \
28     wget https://golang.org/dl/go${go_version}.linux-amd64.tar.gz && \
29     tar xzf go${go_version}.linux-amd64.tar.gz && \
30     ln -s /usr/src/go/bin/go /usr/local/bin/go-${go_version} && \
31     ln -s /usr/src/go/bin/gofmt /usr/local/bin/gofmt-${go_version} && \
32     ln -s /usr/local/bin/go-${go_version} /usr/local/bin/go && \
33     ln -s /usr/local/bin/gofmt-${go_version} /usr/local/bin/gofmt
34
35 # the --mount option requires the experimental syntax enabled (enables
36 # buildkit) on the first line of this file. This Dockerfile must also be built
37 # with the DOCKER_BUILDKIT=1 environment variable set.
38 RUN --mount=type=bind,target=/usr/src/arvados \
39     cd /usr/src/arvados && \
40     go mod download && \
41     cd cmd/arvados-server && \
42     go install
43
44 ###########################################################################################################
45 FROM debian:11-slim as demo
46 ENV DEBIAN_FRONTEND noninteractive
47
48 RUN apt-get update && \
49     apt-get -yq --no-install-recommends -o Acquire::Retries=6 install \
50     build-essential ca-certificates git libpam0g-dev wget
51
52 ENV GOPATH /var/lib/gopath
53 ARG go_version
54
55 RUN cd /usr/src && \
56     wget https://golang.org/dl/go${go_version}.linux-amd64.tar.gz && \
57     tar xzf go${go_version}.linux-amd64.tar.gz && \
58     ln -s /usr/src/go/bin/go /usr/local/bin/go-${go_version} && \
59     ln -s /usr/src/go/bin/gofmt /usr/local/bin/gofmt-${go_version} && \
60     ln -s /usr/local/bin/go-${go_version} /usr/local/bin/go && \
61     ln -s /usr/local/bin/gofmt-${go_version} /usr/local/bin/gofmt
62
63 ARG arvados_version
64 RUN echo arvados_version is git commit $arvados_version
65
66 RUN cd /usr/src && \
67     git clone --no-checkout https://git.arvados.org/arvados.git && \
68     git -C arvados checkout ${arvados_version} && \
69     cd /usr/src/arvados && \
70     go mod download && \
71     cd cmd/arvados-server && \
72     go install
73
74 ###########################################################################################################
75 FROM ${BUILDTYPE} as base
76
77 ###########################################################################################################
78 FROM debian:11
79 ENV DEBIAN_FRONTEND noninteractive
80
81 # The arvbox-specific dependencies are
82 #  gnupg2 runit python3-dev python3-venv shellinabox netcat-openbsd less
83 RUN apt-get update && \
84     apt-get -yq --no-install-recommends -o Acquire::Retries=6 install \
85     gnupg2 runit python3-dev python3-venv shellinabox netcat-openbsd less vim-tiny && \
86     apt-get clean
87
88 ENV GOPATH /var/lib/gopath
89 RUN echo buildtype is $BUILDTYPE
90
91 RUN mkdir -p $GOPATH/bin/
92 COPY --from=base $GOPATH/bin/arvados-server $GOPATH/bin/arvados-server
93 RUN $GOPATH/bin/arvados-server --version
94 RUN $GOPATH/bin/arvados-server install -type test
95
96 # Set up a virtualenv for all Python tools in arvbox.
97 # This is used mainly by the `sdk` service, but `doc` and internal scripts
98 # also rely on it.
99 # 1. Install wheel just to modernize the virtualenv.
100 # 2. Install setuptools as an sdk build dependency; PyYAML for all tests
101 #    and yml_override.py; and pdoc for the doc service.
102 # Everything else is installed by the sdk service on boot.
103 RUN python3 -m venv /opt/arvados-py \
104  && /opt/arvados-py/bin/pip install --no-cache-dir wheel \
105  && /opt/arvados-py/bin/pip install --no-cache-dir setuptools PyYAML pdoc
106
107 RUN /etc/init.d/postgresql start && \
108     su postgres -c 'dropuser arvados' && \
109     su postgres -c 'createuser -s arvbox' && \
110     /etc/init.d/postgresql stop
111
112 VOLUME /var/lib/docker
113 VOLUME /var/log/nginx
114 VOLUME /etc/ssl/private
115
116 ARG workdir
117
118 ADD $workdir/8D81803C0EBFCD88.asc /tmp/
119 RUN apt-key add --no-tty /tmp/8D81803C0EBFCD88.asc && \
120     rm -f /tmp/8D81803C0EBFCD88.asc
121
122 # docker is now installed by arvados-server install
123 # RUN mkdir -p /etc/apt/sources.list.d && \
124 #     echo deb https://download.docker.com/linux/debian/ buster stable > /etc/apt/sources.list.d/docker.list && \
125 #     apt-get update && \
126 #     apt-get -yq --no-install-recommends install docker-ce=5:20.10.6~3-0~debian-buster && \
127 #     apt-get clean
128
129 # Set UTF-8 locale
130 RUN echo en_US.UTF-8 UTF-8 > /etc/locale.gen && locale-gen
131 ENV LANG en_US.UTF-8
132 ENV LANGUAGE en_US:en
133 ENV LC_ALL en_US.UTF-8
134
135 ARG arvados_version
136 RUN echo arvados_version is git commit $arvados_version
137
138 COPY $workdir/fuse.conf /etc/
139
140 COPY $workdir/gitolite.rc \
141     $workdir/keep-setup.sh $workdir/common.sh $workdir/createusers.sh \
142     $workdir/logger $workdir/runsu.sh $workdir/waitforpostgres.sh \
143     $workdir/yml_override.py $workdir/api-setup.sh \
144     $workdir/go-setup.sh $workdir/devenv.sh $workdir/cluster-config.sh $workdir/edit_users.py \
145     /usr/local/lib/arvbox/
146
147 COPY $workdir/runit /etc/runit
148
149 # arvbox mounts a docker volume at $ARVADOS_CONTAINER_PATH, make sure that that
150 # doesn't overlap with the directory where `arvados-server install -type test`
151 # put everything (/var/lib/arvados)
152 ENV ARVADOS_CONTAINER_PATH /var/lib/arvados-arvbox
153
154 RUN /bin/ln -s /var/lib/arvados/bin/ruby /usr/local/bin/
155
156 # Start the supervisor.
157 ENV SVDIR /etc/service
158 STOPSIGNAL SIGINT
159 CMD ["/etc/runit/2"]