-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
162 lines (119 loc) · 4.45 KB
/
Copy pathDockerfile
File metadata and controls
162 lines (119 loc) · 4.45 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
ARG TARGET=production
# Stage 1: Dependencies
FROM node:26.4.0-bullseye AS dependencies
WORKDIR /app
COPY package.json yarn.lock .yarnrc.yml version.js ./
COPY .yarn ./.yarn
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
RUN npm install -g corepack \
&& corepack enable \
&& corepack prepare "$(node -p "require('./package.json').packageManager")" --activate \
&& yarn install --immutable
# Stage 2: Development
FROM node:26.4.0-slim AS development
# Let's use bash as a default shell with login each time
SHELL ["/bin/bash", "--login", "-c"]
# Update package list and install necessary libraries
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
bash \
bash-completion \
curl \
fish \
git \
jq \
locales \
make \
nano \
python3-dev \
python3-pip \
python3-setuptools \
sudo \
unzip \
&& rm -rf /var/lib/apt/lists/*
# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
&& locale-gen
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
RUN npm install -g corepack \
&& corepack enable
WORKDIR /app
# Copy source code to container
COPY . .
RUN corepack prepare "$(node -p "require('./package.json').packageManager")" --activate
# Add necessary stuff to bash autocomplete
RUN echo 'source /usr/share/bash-completion/bash_completion' >> /etc/bash.bashrc \
&& curl https://raw.githubusercontent.com/dsifford/yarn-completion/master/yarn-completion.bash >> /etc/bash.bashrc \
&& printf '\nNG_COMMANDS="add build config doc e2e generate help lint new run serve test update version xi18n"\ncomplete -W "$NG_COMMANDS" ng\n' >> /etc/bash.bashrc
# Link `ng` command and set entrypoint with executable permissions
RUN ln -s /app/node_modules/.bin/ng /usr/local/bin/ng \
&& chmod +x docker-entrypoint-dev.sh
# Add node user to sudo group and set password to `node`
RUN usermod -a -G sudo node \
&& usermod -p $(perl -e 'print crypt($ARGV[0], "password")' 'node') node \
&& echo 'node ALL=(ALL) ALL' >> /etc/sudoers
RUN mkdir -p /home/node/.config/fish/completions \
&& mkdir -p /home/node/.config/fish/functions \
&& mkdir -p /home/node/.local/share \
&& chmod 777 -R /home/node
USER node
RUN pip3 install thefuck --user --no-warn-script-location --break-system-packages
# thefuck 3.32 still imports deprecated `imp`; patch it for Python 3.13.
RUN python3 - <<'PY'
from pathlib import Path
import site
base = Path(site.getusersitepackages()) / 'thefuck'
compat = """from importlib.util import module_from_spec, spec_from_file_location
def load_source(name, path):
spec = spec_from_file_location(name, path)
if spec is None or spec.loader is None:
raise ImportError(f\"Cannot load module {name!r} from {path!r}\")
module = module_from_spec(spec)
spec.loader.exec_module(module)
return module
"""
for filename in ('conf.py', 'types.py'):
path = base / filename
if not path.exists():
raise FileNotFoundError(path)
text = path.read_text()
if 'from imp import load_source\n' not in text:
raise RuntimeError(f'Missing expected import in {path}')
text = text.replace('from imp import load_source\n', compat, 1)
path.write_text(text)
PY
RUN fish -c 'curl -sL git.io/fisher | source && fisher install jorgebucaran/fisher' \
&& fish -c 'fisher install jorgebucaran/nvm.fish'
COPY ./docker/fish /home/node/.config/fish/
USER root
RUN chmod 777 -R /home/node /tmp \
&& rm -rf /tmp/fish.node
USER node
# User environment
ENV PATH="$PATH:/home/node/.local/bin"
ENV XDG_RUNTIME_PATH=/home/node/.tmp
RUN echo 'if command -v thefuck >/dev/null 2>&1; then eval "$(thefuck --alias 2>/dev/null)" || true; fi' >> /home/node/.bashrc
# Expose port 4200 outside
EXPOSE 4200
# Set custom entrypoint for dev container
ENTRYPOINT ["/app/docker-entrypoint-dev.sh"]
# Stage 3: Builder
FROM dependencies AS builder
WORKDIR /app
# Copy source code
COPY . .
# Build the application
RUN yarn build-prod
# Stage 4: Production
FROM nginx:1.31.2-alpine-slim AS production
RUN apk update \
&& apk add --no-cache libcrypto3=3.5.8-r0 \
&& rm -rf /var/cache/apk/*
# Copy nginx configuration and build application inside the final container
COPY --from=builder /app/docker/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/dist/angular-frontend/browser /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]