-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
90 lines (72 loc) · 3.31 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
86
87
88
89
90
# syntax=docker/dockerfile:1.7-labs
# ^^^ needed for COPY --exclude
# This is the SHA of a multi-arch manifest, so it'll use the native
# container on amd64 / arm64.
ARG BASE=ghcr.io/r-lib/rig/ubuntu-22.04-release@sha256:1dc2de2cf32dd10945a4ed3714ae35e73b01e1ea47f458c3e9dc82eef016a3e2
# -------------------------------------------------------------------------
# build stage has stuff needed for everything, e.g. R, hard dependencies
# -------------------------------------------------------------------------
FROM --platform=linux/amd64 ${BASE} AS build
COPY ./DESCRIPTION .
RUN R -q -e 'pak::pkg_install("deps::.", lib = .Library); pak::pak_cleanup(force = TRUE)' && \
apt-get clean && \
rm -rf DESCRIPTION /tmp/*
# -------------------------------------------------------------------------
# test-deps stage have stuff needed to run the tests and also for dev
# -------------------------------------------------------------------------
FROM build AS test-deps
ENV NOT_CRAN=true
COPY ./DESCRIPTION .
RUN R -q -e 'pak::pkg_install("deps::.", dependencies = TRUE)'; \
apt-get clean && \
rm -rf DESCRIPTION /tmp/*
# -------------------------------------------------------------------------
# This stage actually runs the tests + test coverage
# -------------------------------------------------------------------------
FROM test-deps AS test
COPY . /app
WORKDIR /app
RUN if [ -d tests ]; then \
R -q -e 'testthat::test_local()'; \
R -q -e 'covr::to_cobertura(print(covr::package_coverage()))'; \
fi
ARG GITHUB_SHA
ARG GITHUB_REPOSITORY
ARG GITHUB_REF_NAME
RUN --mount=type=secret,id=CODECOV_TOKEN \
if [ -d tests ] && [ -f /run/secrets/CODECOV_TOKEN ]; then \
apt-get update && apt-get install -y git && \
R -q -e 'download.file("https://cli.codecov.io/latest/linux/codecov", "/usr/local/bin/codecov")' && \
chmod +x /usr/local/bin/codecov && \
codecov upload-process --disable-search -f cobertura.xml --plugin noop \
--git-service github --token `cat /run/secrets/CODECOV_TOKEN` \
--sha ${GITHUB_SHA} --slug ${GITHUB_REPOSITORY} \
--branch ${GITHUB_REF_NAME}; \
fi
# -------------------------------------------------------------------------
# production stage, this is deployed. Has the extra stuff only needed
# for deployment
# -------------------------------------------------------------------------
FROM build AS prod
COPY --from=test /tmp/dummy* /tmp/
# copy everything, except the tests
COPY --exclude=tests . /app
# tools neeed for prod
RUN apt-get update && \
apt-get install -y git rsync && \
apt-get clean
# -------------------------------------------------------------------------
# for development. This is the default, so devcontainers run this.
# it has the test-deps, plus stuff only needed for development
# -------------------------------------------------------------------------
FROM test-deps AS dev
RUN R -q -e 'pak::pkg_install(c("devtools", "usethis", "profvis"))'
RUN R -q -e 'pak::pkg_install("languageserver")'
RUN apt-get update && \
apt-get install -y openssh-server && \
apt-get clean
RUN echo PermitRootLogin yes >> /etc/ssh/sshd_config && \
echo PermitEmptyPasswords yes >> /etc/ssh/sshd_config && \
echo Port 2222 >> /etc/ssh/sshd_config && \
passwd -d root
RUN git config --global --add safe.directory '/workspaces/*'