-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
118 lines (91 loc) · 3.86 KB
/
Copy pathDockerfile
File metadata and controls
118 lines (91 loc) · 3.86 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Stage I: Runtime ============================================================
FROM node:lts-buster-slim AS runtime
RUN echo 'APT::Acquire::Retries "3";' > /etc/apt/apt.conf.d/80-retries \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
# Stage II: Testing ===========================================================
FROM runtime AS testing
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
git
# Receive the APP_PATH argument:
ARG APP_PATH=/icalialabs/xtendize
# Receive the developer user's UID and USER:
ARG DEVELOPER_UID=1000
ARG DEVELOPER_USERNAME=you
# Replicate the developer user in the development image:
RUN id ${DEVELOPER_UID} \
|| useradd -r -m -u ${DEVELOPER_UID} \
--shell /bin/bash -c "Developer User,,," ${DEVELOPER_USERNAME}
# Ensure the developer user's home directory and APP_PATH are owned by him/her:
# (A workaround to a side effect of setting WORKDIR before creating the user)
RUN mkdir -p ${APP_PATH} && chown -R ${DEVELOPER_UID}:node ${APP_PATH}
# Add the project's executable path to the system PATH:
ENV PATH=${APP_PATH}/bin:$PATH
# Configure the app dir as the working dir:
WORKDIR ${APP_PATH}
# Switch to the developer user:
USER ${DEVELOPER_UID}
# Copy and install the project dependency lists into the container image:
COPY --chown=${DEVELOPER_UID} package.json yarn.lock ${APP_PATH}/
RUN yarn install
ENV PATH=${APP_PATH}/node_modules/.bin:$PATH
# Stage III: Development =======================================================
FROM testing AS development
# Receive the APP_PATH argument:
ARG APP_PATH=/icalialabs/xtendize
# Receive the developer user's UID and USER:
ARG DEVELOPER_UID=1000
# Switch to "root" user to install system dependencies such as sudo:
USER root
# Install sudo, along with other system dependencies required at development
# time:
RUN apt-get install -y --no-install-recommends \
# Adding bash autocompletion as git without autocomplete is a pain...
bash-completion \
#glibc?
groff less \
# gpg & gpgconf is used to get Git Commit GPG Signatures working inside the
# VSCode devcontainer:
gpg \
# OpenSSH Client required to push changes to Github via SSH:
openssh-client \
# /proc file system utilities: (watch, ps):
procps \
# Sudo will be used to install/configure system stuff if needed during dev:
sudo \
# Vim might be used to edit files when inside the container (git, etc):
vim \
unzip
# Add the developer user to the sudoers list:
RUN export USERNAME=$(getent passwd ${DEVELOPER_UID} | cut -d: -f1) \
&& echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" \
| tee "/etc/sudoers.d/${USERNAME}"
# Persist bash history between runs
# - See https://code.visualstudio.com/docs/remote/containers-advanced#_persist-bash-history-between-runs
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/command-history/.bash_history" \
&& mkdir /command-history \
&& touch /command-history/.bash_history \
&& chown -R node /command-history \
&& echo $SNIPPET >> "/home/node/.bashrc"
# Switch to the developer user:
USER ${DEVELOPER_UID}
# Create the directories used to save Visual Studio Code extensions inside the
# dev container:
RUN mkdir -p ~/.vscode-server/extensions ~/.vscode-server-insiders/extensions
# Stage IV: Builder ============================================================
FROM testing AS builder
ARG APP_PATH=/icalialabs/xtendize
ARG DEVELOPER_UID=1000
COPY --chown=${DEVELOPER_UID} . ${APP_PATH}/
RUN yarn build
# Stage V: Release =============================================================
FROM runtime AS release
ARG APP_PATH=/icalialabs/xtendize
COPY --from=builder --chown=node:node ${APP_PATH}/lib /icalialabs/xtendize/lib
COPY --from=builder --chown=node:node ${APP_PATH}/package.json ${APP_PATH}/LICENSE /icalialabs/xtendize/
WORKDIR /icalialabs/xtendize
CMD [ "find", "." ]