Skip to content

Commit 9762158

Browse files
committed
revert deleting dogfood Docker stuff
Signed-off-by: Spike Curtis <spike@coder.com>
1 parent 2805dda commit 9762158

40 files changed

+578
-0
lines changed

dogfood/Dockerfile

Lines changed: 348 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,348 @@
1+
FROM rust:slim AS rust-utils
2+
# Install rust helper programs
3+
# ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
4+
ENV CARGO_INSTALL_ROOT=/tmp/
5+
RUN cargo install exa bat ripgrep typos-cli watchexec-cli
6+
7+
FROM ubuntu:jammy AS go
8+
9+
RUN apt-get update && apt-get install --yes curl gcc
10+
# Install Go manually, so that we can control the version
11+
ARG GO_VERSION=1.20.7
12+
RUN mkdir --parents /usr/local/go
13+
14+
# Boring Go is needed to build FIPS-compliant binaries.
15+
RUN curl --silent --show-error --location \
16+
"https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" \
17+
-o /usr/local/go.tar.gz
18+
19+
RUN tar --extract --gzip --directory=/usr/local/go --file=/usr/local/go.tar.gz --strip-components=1
20+
21+
ENV PATH=$PATH:/usr/local/go/bin
22+
23+
# Install Go utilities.
24+
ARG GOPATH="/tmp/"
25+
RUN mkdir --parents "$GOPATH" && \
26+
# moq for Go tests.
27+
go install github.com/matryer/moq@v0.2.3 && \
28+
# swag for Swagger doc generation
29+
go install github.com/swaggo/swag/cmd/swag@v1.7.4 && \
30+
# go-swagger tool to generate the go coder api client
31+
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.28.0 && \
32+
# goimports for updating imports
33+
go install golang.org/x/tools/cmd/goimports@v0.1.7 && \
34+
# protoc-gen-go is needed to build sysbox from source
35+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30 && \
36+
# drpc support for v2
37+
go install storj.io/drpc/cmd/protoc-gen-go-drpc@v0.0.33 && \
38+
# migrate for migration support for v2
39+
go install github.com/golang-migrate/migrate/v4/cmd/migrate@v4.15.1 && \
40+
# goreleaser for compiling v2 binaries
41+
go install github.com/goreleaser/goreleaser@v1.6.1 && \
42+
# Install the latest version of gopls for editors that support
43+
# the language server protocol
44+
go install golang.org/x/tools/gopls@latest && \
45+
# gotestsum makes test output more readable
46+
go install gotest.tools/gotestsum@v1.9.0 && \
47+
# goveralls collects code coverage metrics from tests
48+
# and sends to Coveralls
49+
go install github.com/mattn/goveralls@v0.0.11 && \
50+
# kind for running Kubernetes-in-Docker, needed for tests
51+
go install sigs.k8s.io/kind@v0.10.0 && \
52+
# helm-docs generates our Helm README based on a template and the
53+
# charts and values files
54+
go install github.com/norwoodj/helm-docs/cmd/helm-docs@v1.5.0 && \
55+
# sqlc for Go code generation
56+
go install github.com/sqlc-dev/sqlc/cmd/sqlc@v1.20.0 && \
57+
# gcr-cleaner-cli used by CI to prune unused images
58+
go install github.com/sethvargo/gcr-cleaner/cmd/gcr-cleaner-cli@v0.5.1 && \
59+
# ruleguard for checking custom rules, without needing to run all of
60+
# golangci-lint. Check the go.mod in the release of golangci-lint that
61+
# we're using for the version of go-critic that it embeds, then check
62+
# the version of ruleguard in go-critic for that tag.
63+
go install github.com/quasilyte/go-ruleguard/cmd/ruleguard@v0.3.13 && \
64+
# go-fuzz for fuzzy testing. they don't publish releases so we rely on latest.
65+
go install github.com/dvyukov/go-fuzz/go-fuzz@latest && \
66+
go install github.com/dvyukov/go-fuzz/go-fuzz-build@latest && \
67+
# go-releaser for building 'fat binaries' that work cross-platform
68+
go install github.com/goreleaser/goreleaser@v1.6.1 && \
69+
go install mvdan.cc/sh/v3/cmd/shfmt@latest && \
70+
# nfpm is used with `make build` to make release packages
71+
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.16.0 && \
72+
# yq v4 is used to process yaml files in coder v2. Conflicts with
73+
# yq v3 used in v1.
74+
go install github.com/mikefarah/yq/v4@v4.30.6 && \
75+
mv /tmp/bin/yq /tmp/bin/yq4 && \
76+
go install github.com/golang/mock/mockgen@v1.6.0
77+
78+
FROM gcr.io/coder-dev-1/alpine:3.18 as proto
79+
WORKDIR /tmp
80+
RUN apk add curl unzip
81+
RUN curl -L -o protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v23.3/protoc-23.3-linux-x86_64.zip
82+
RUN unzip protoc.zip
83+
84+
FROM ubuntu:jammy
85+
86+
SHELL ["/bin/bash", "-c"]
87+
88+
# Updated certificates are necessary to use the teraswitch mirror.
89+
# This must be ran before copying in configuration since the config replaces
90+
# the default mirror with teraswitch.
91+
RUN apt-get update && apt-get install --yes ca-certificates
92+
93+
COPY files /
94+
95+
# Install packages from apt repositories
96+
ARG DEBIAN_FRONTEND="noninteractive"
97+
98+
RUN apt-get update --quiet && apt-get install --yes \
99+
apt-transport-https \
100+
apt-utils \
101+
bash \
102+
bash-completion \
103+
bats \
104+
bind9-dnsutils \
105+
build-essential \
106+
ca-certificates \
107+
cmake \
108+
crypto-policies \
109+
curl \
110+
fd-find \
111+
file \
112+
git \
113+
gnupg \
114+
graphviz \
115+
htop \
116+
httpie \
117+
inetutils-tools \
118+
iproute2 \
119+
iputils-ping \
120+
iputils-tracepath \
121+
jq \
122+
language-pack-en \
123+
less \
124+
lsb-release \
125+
man \
126+
meld \
127+
net-tools \
128+
openjdk-11-jdk-headless \
129+
openssh-server \
130+
openssl \
131+
libssl-dev \
132+
pkg-config \
133+
python3 \
134+
python3-pip \
135+
rsync \
136+
shellcheck \
137+
strace \
138+
sudo \
139+
tcptraceroute \
140+
termshark \
141+
traceroute \
142+
vim \
143+
wget \
144+
xauth \
145+
zip \
146+
ncdu \
147+
cargo \
148+
asciinema \
149+
zsh \
150+
ansible \
151+
neovim \
152+
google-cloud-sdk \
153+
google-cloud-sdk-datastore-emulator \
154+
kubectl \
155+
postgresql-13 \
156+
containerd.io \
157+
docker-ce \
158+
docker-ce-cli \
159+
docker-compose-plugin \
160+
packer \
161+
terraform \
162+
fish \
163+
unzip \
164+
zstd \
165+
screen \
166+
gettext-base && \
167+
# Delete package cache to avoid consuming space in layer
168+
apt-get clean && \
169+
# Configure FIPS-compliant policies
170+
update-crypto-policies --set FIPS
171+
172+
# Install the docker buildx component.
173+
RUN DOCKER_BUILDX_VERSION=$(curl -s "https://api.github.com/repos/docker/buildx/releases/latest" | grep '"tag_name":' | sed -E 's/.*"(v[^"]+)".*/\1/') && \
174+
mkdir -p /usr/local/lib/docker/cli-plugins && \
175+
curl -Lo /usr/local/lib/docker/cli-plugins/docker-buildx "https://github.com/docker/buildx/releases/download/${DOCKER_BUILDX_VERSION}/buildx-${DOCKER_BUILDX_VERSION}.linux-amd64" && \
176+
chmod a+x /usr/local/lib/docker/cli-plugins/docker-buildx
177+
178+
# See https://github.com/cli/cli/issues/6175#issuecomment-1235984381 for proof
179+
# the apt repository is unreliable
180+
RUN GH_CLI_VERSION=$(curl -s "https://api.github.com/repos/cli/cli/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/') && \
181+
curl -L https://github.com/cli/cli/releases/download/v${GH_CLI_VERSION}/gh_${GH_CLI_VERSION}_linux_amd64.deb -o gh.deb && \
182+
dpkg -i gh.deb && \
183+
rm gh.deb
184+
185+
# Install Lazygit
186+
# See https://github.com/jesseduffield/lazygit#ubuntu
187+
RUN LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v*([^"]+)".*/\1/') && \
188+
curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" && \
189+
tar xf lazygit.tar.gz -C /usr/local/bin lazygit
190+
191+
# Install frontend utilities
192+
RUN apt-get update && \
193+
# Node.js (from nodesource) and Yarn (from yarnpkg)
194+
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
195+
apt-get install --yes --quiet \
196+
nodejs yarn \
197+
# Install browsers for e2e testing
198+
google-chrome-stable microsoft-edge-beta && \
199+
# Pre-install system dependencies that Playwright needs. npx doesn't work here
200+
# for some reason. See https://github.com/microsoft/playwright-cli/issues/136
201+
npm i -g playwright@1.36.2 pnpm@^8 && playwright install-deps && \
202+
npm cache clean --force
203+
204+
# Ensure PostgreSQL binaries are in the users $PATH.
205+
RUN update-alternatives --install /usr/local/bin/initdb initdb /usr/lib/postgresql/13/bin/initdb 100 && \
206+
update-alternatives --install /usr/local/bin/postgres postgres /usr/lib/postgresql/13/bin/postgres 100
207+
208+
# Create links for injected dependencies
209+
RUN ln --symbolic /var/tmp/coder/coder-cli/coder /usr/local/bin/coder && \
210+
ln --symbolic /var/tmp/coder/code-server/bin/code-server /usr/local/bin/code-server
211+
212+
# Disable the PostgreSQL systemd service.
213+
# Coder uses a custom timescale container to test the database instead.
214+
RUN systemctl disable \
215+
postgresql
216+
217+
# Configure systemd services for CVMs
218+
RUN systemctl enable \
219+
docker \
220+
ssh
221+
222+
# Install tools with published releases, where that is the
223+
# preferred/recommended installation method.
224+
ARG CLOUD_SQL_PROXY_VERSION=2.2.0 \
225+
DIVE_VERSION=0.10.0 \
226+
DOCKER_GCR_VERSION=2.1.8 \
227+
GOLANGCI_LINT_VERSION=1.52.2 \
228+
GRYPE_VERSION=0.61.1 \
229+
HELM_VERSION=3.12.0 \
230+
KUBE_LINTER_VERSION=0.6.3 \
231+
KUBECTX_VERSION=0.9.4 \
232+
STRIPE_VERSION=1.14.5 \
233+
TERRAGRUNT_VERSION=0.45.11 \
234+
TRIVY_VERSION=0.41.0
235+
236+
# cloud_sql_proxy, for connecting to cloudsql instances
237+
# the upstream go.mod prevents this from being installed with go install
238+
RUN curl --silent --show-error --location --output /usr/local/bin/cloud_sql_proxy "https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v${CLOUD_SQL_PROXY_VERSION}/cloud-sql-proxy.linux.amd64" && \
239+
chmod a=rx /usr/local/bin/cloud_sql_proxy && \
240+
# dive for scanning image layer utilization metrics in CI
241+
curl --silent --show-error --location "https://github.com/wagoodman/dive/releases/download/v${DIVE_VERSION}/dive_${DIVE_VERSION}_linux_amd64.tar.gz" | \
242+
tar --extract --gzip --directory=/usr/local/bin --file=- dive && \
243+
# docker-credential-gcr is a Docker credential helper for pushing/pulling
244+
# images from Google Container Registry and Artifact Registry
245+
curl --silent --show-error --location "https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v${DOCKER_GCR_VERSION}/docker-credential-gcr_linux_amd64-${DOCKER_GCR_VERSION}.tar.gz" | \
246+
tar --extract --gzip --directory=/usr/local/bin --file=- docker-credential-gcr && \
247+
# golangci-lint performs static code analysis for our Go code
248+
curl --silent --show-error --location "https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_LINT_VERSION}/golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64.tar.gz" | \
249+
tar --extract --gzip --directory=/usr/local/bin --file=- --strip-components=1 "golangci-lint-${GOLANGCI_LINT_VERSION}-linux-amd64/golangci-lint" && \
250+
# Anchore Grype for scanning container images for security issues
251+
curl --silent --show-error --location "https://github.com/anchore/grype/releases/download/v${GRYPE_VERSION}/grype_${GRYPE_VERSION}_linux_amd64.tar.gz" | \
252+
tar --extract --gzip --directory=/usr/local/bin --file=- grype && \
253+
# Helm is necessary for deploying Coder
254+
curl --silent --show-error --location "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | \
255+
tar --extract --gzip --directory=/usr/local/bin --file=- --strip-components=1 linux-amd64/helm && \
256+
# kube-linter for linting Kubernetes objects, including those
257+
# that Helm generates from our charts
258+
curl --silent --show-error --location "https://github.com/stackrox/kube-linter/releases/download/${KUBE_LINTER_VERSION}/kube-linter-linux" --output /usr/local/bin/kube-linter && \
259+
# kubens and kubectx for managing Kubernetes namespaces and contexts
260+
curl --silent --show-error --location "https://github.com/ahmetb/kubectx/releases/download/v${KUBECTX_VERSION}/kubectx_v${KUBECTX_VERSION}_linux_x86_64.tar.gz" | \
261+
tar --extract --gzip --directory=/usr/local/bin --file=- kubectx && \
262+
curl --silent --show-error --location "https://github.com/ahmetb/kubectx/releases/download/v${KUBECTX_VERSION}/kubens_v${KUBECTX_VERSION}_linux_x86_64.tar.gz" | \
263+
tar --extract --gzip --directory=/usr/local/bin --file=- kubens && \
264+
# stripe for coder.com billing API
265+
curl --silent --show-error --location "https://github.com/stripe/stripe-cli/releases/download/v${STRIPE_VERSION}/stripe_${STRIPE_VERSION}_linux_x86_64.tar.gz" | \
266+
tar --extract --gzip --directory=/usr/local/bin --file=- stripe && \
267+
# terragrunt for running Terraform and Terragrunt files
268+
curl --silent --show-error --location --output /usr/local/bin/terragrunt "https://github.com/gruntwork-io/terragrunt/releases/download/v${TERRAGRUNT_VERSION}/terragrunt_linux_amd64" && \
269+
chmod a=rx /usr/local/bin/terragrunt && \
270+
# AquaSec Trivy for scanning container images for security issues
271+
curl --silent --show-error --location "https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz" | \
272+
tar --extract --gzip --directory=/usr/local/bin --file=- trivy
273+
274+
# Add Vercel globally. We can't install it in packages.json, because it
275+
# includes Go files which make golangci-lint unhappy.
276+
RUN yarn global add --prefix=/usr/local \
277+
vercel \
278+
typescript \
279+
typescript-language-server \
280+
prettier && \
281+
yarn cache clean
282+
283+
# We use yq during "make deploy" to manually substitute out fields in
284+
# our helm values.yaml file. See https://github.com/helm/helm/issues/3141
285+
#
286+
# TODO: update to 4.x, we can't do this now because it included breaking
287+
# changes (yq w doesn't work anymore)
288+
# RUN curl --silent --show-error --location "https://github.com/mikefarah/yq/releases/download/v4.9.0/yq_linux_amd64.tar.gz" | \
289+
# tar --extract --gzip --directory=/usr/local/bin --file=- ./yq_linux_amd64 && \
290+
# mv /usr/local/bin/yq_linux_amd64 /usr/local/bin/yq
291+
292+
RUN curl --silent --show-error --location --output /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/3.3.0/yq_linux_amd64" && \
293+
chmod a=rx /usr/local/bin/yq
294+
295+
# Install GoLand.
296+
RUN mkdir --parents /usr/local/goland && \
297+
curl --silent --show-error --location "https://download.jetbrains.com/go/goland-2021.2.tar.gz" | \
298+
tar --extract --gzip --directory=/usr/local/goland --file=- --strip-components=1 && \
299+
ln --symbolic /usr/local/goland/bin/goland.sh /usr/local/bin/goland
300+
301+
# Install Antlrv4, needed to generate paramlang lexer/parser
302+
RUN curl --silent --show-error --location --output /usr/local/lib/antlr-4.9.2-complete.jar "https://www.antlr.org/download/antlr-4.9.2-complete.jar"
303+
ENV CLASSPATH="/usr/local/lib/antlr-4.9.2-complete.jar:${PATH}"
304+
305+
# Add coder user and allow use of docker/sudo
306+
RUN useradd coder \
307+
--create-home \
308+
--shell=/bin/bash \
309+
--groups=docker \
310+
--uid=1000 \
311+
--user-group
312+
313+
# Adjust OpenSSH config
314+
RUN echo "PermitUserEnvironment yes" >>/etc/ssh/sshd_config && \
315+
echo "X11Forwarding yes" >>/etc/ssh/sshd_config && \
316+
echo "X11UseLocalhost no" >>/etc/ssh/sshd_config
317+
318+
# We avoid copying the extracted directory since COPY slows to minutes when there
319+
# are a lot of small files.
320+
COPY --from=go /usr/local/go.tar.gz /usr/local/go.tar.gz
321+
RUN mkdir /usr/local/go && \
322+
tar --extract --gzip --directory=/usr/local/go --file=/usr/local/go.tar.gz --strip-components=1
323+
324+
ENV PATH=$PATH:/usr/local/go/bin
325+
326+
RUN update-alternatives --install /usr/local/bin/gofmt gofmt /usr/local/go/bin/gofmt 100
327+
328+
COPY --from=go /tmp/bin /usr/local/bin
329+
COPY --from=rust-utils /tmp/bin /usr/local/bin
330+
COPY --from=proto /tmp/bin /usr/local/bin
331+
COPY --from=proto /tmp/include /usr/local/bin/include
332+
333+
USER coder
334+
335+
# Ensure go bins are in the 'coder' user's path. Note that no go bins are
336+
# installed in this docker file, as they'd be mounted over by the persistent
337+
# home volume.
338+
ENV PATH="/home/coder/go/bin:${PATH}"
339+
340+
# This setting prevents Go from using the public checksum database for
341+
# our module path prefixes. It is required because these are in private
342+
# repositories that require authentication.
343+
#
344+
# For details, see: https://golang.org/ref/mod#private-modules
345+
ENV GOPRIVATE="coder.com,cdr.dev,go.coder.com,github.com/cdr,github.com/coder"
346+
347+
# Increase memory allocation to NodeJS
348+
ENV NODE_OPTIONS="--max-old-space-size=8192"

dogfood/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.PHONY: docker-build docker-push
2+
3+
branch=$(shell git rev-parse --abbrev-ref HEAD)
4+
build_tag=codercom/oss-dogfood:${branch}
5+
6+
build:
7+
DOCKER_BUILDKIT=1 docker build . -t ${build_tag}
8+
9+
push: build
10+
docker push ${build_tag}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Do not install recommended packages by default
2+
APT::Install-Recommends "0";
3+
4+
// Do not install suggested packages by default (this is already
5+
// the Ubuntu default)
6+
APT::Install-Suggests "0";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APT::Acquire::Retries "3";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Ignore all packages from this repository by default
2+
Package: *
3+
Pin: origin download.docker.com
4+
Pin-Priority: 1
5+
6+
# Docker Community Edition
7+
Package: docker-ce
8+
Pin: origin download.docker.com
9+
Pin-Priority: 500
10+
11+
# Docker command-line tool
12+
Package: docker-ce-cli
13+
Pin: origin download.docker.com
14+
Pin-Priority: 500
15+
16+
# containerd runtime
17+
Package: containerd.io
18+
Pin: origin download.docker.com
19+
Pin-Priority: 500
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ignore all packages from this repository by default
2+
Package: *
3+
Pin: origin cli.github.com
4+
Pin-Priority: 1
5+
6+
Package: gh
7+
Pin: origin cli.github.com
8+
Pin-Priority: 500

0 commit comments

Comments
 (0)