-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multi-stage dockerfile and fix docker image bugs
- Loading branch information
saravahdatipour
committed
Jan 13, 2025
1 parent
f690787
commit 7067fe2
Showing
4 changed files
with
70 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,45 @@ | ||
# Stage 1: download and build the webpages | ||
FROM python:3.9-slim AS python-build | ||
COPY . . | ||
RUN pip install Jinja2 requests \ | ||
&& python3 download_repos.py \ | ||
&& python3 -u update.py | ||
# --- Stage 1 Node build | ||
FROM node:18-slim AS node-build | ||
|
||
WORKDIR /app | ||
|
||
COPY src ./ | ||
COPY webpack.config.js yarn.lock package.json ./ | ||
|
||
# Stage 2: install dependencies and build assets | ||
FROM node:18 AS node-build | ||
ENV NODE_OPTIONS=--openssl-legacy-provider | ||
RUN yarn install --frozen-lockfile | ||
|
||
ENV NODE_OPTIONS="--openssl-legacy-provider" | ||
COPY . . | ||
RUN yarn && yarn build | ||
|
||
# Stage 3: host | ||
FROM debian:bullseye-slim | ||
RUN apt-get update && \ | ||
apt-get install -y apache2 && \ | ||
rm -rf /var/lib/apt/lists/* && \ | ||
echo 'Alias /en /var/www/html/en' >> /etc/apache2/apache2.conf && \ | ||
echo 'Alias /nl /var/www/html/nl' >> /etc/apache2/apache2.conf && \ | ||
echo '<LocationMatch "^/$">' >> /etc/apache2/apache2.conf && \ | ||
echo ' Require all denied' >> /etc/apache2/apache2.conf && \ | ||
echo '</LocationMatch>' >> /etc/apache2/apache2.conf | ||
COPY --from=python-build /en/ /var/www/html/en/ | ||
COPY --from=python-build /nl/ /var/www/html/nl/ | ||
COPY --from=python-build /repos/ /var/www/html/repos/ | ||
COPY --from=python-build index.json /var/www/html/ | ||
COPY --from=node-build /script.js /var/www/html/ | ||
RUN yarn build | ||
|
||
# --- Stage 2 Python build | ||
FROM python:3.9-slim AS python-build | ||
|
||
WORKDIR /app | ||
COPY --from=node-build /app ./ | ||
|
||
COPY download_repos.py update.py config.json ./ | ||
RUN ls -l /app | ||
|
||
RUN pip install --no-cache-dir Jinja2 requests && \ | ||
python3 download_repos.py && \ | ||
python3 -u update.py | ||
|
||
# --- Stage 3: Final nginx stage | ||
FROM nginx:stable | ||
|
||
COPY nginx.conf /etc/nginx/conf.d/default.conf | ||
|
||
COPY --from=python-build /app/en/ /var/www/html/en/ | ||
COPY --from=python-build /app/nl/ /var/www/html/nl/ | ||
COPY --from=python-build /app/repos/ /var/www/html/repos/ | ||
COPY --from=python-build /app/index.json /var/www/html/ | ||
COPY --from=node-build /app/script.js /var/www/html/ | ||
COPY style.css logo.svg /var/www/html/ | ||
|
||
RUN chown -R nginx:nginx /var/www/html && \ | ||
chmod -R 755 /var/www/html | ||
|
||
EXPOSE 80 | ||
CMD ["apache2ctl", "-D", "FOREGROUND"] | ||
|
||
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3.8' | ||
|
||
services: | ||
attribute-index: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- "80:80" | ||
environment: | ||
- NODE_OPTIONS=--openssl-legacy-provider | ||
restart: unless-stopped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
server { | ||
listen 80; | ||
server_name 127.0.0.1; | ||
root /var/www/html; | ||
index index.html; | ||
charset utf-8; | ||
|
||
location / { | ||
if ($uri = /) { | ||
return 301 /en; | ||
} | ||
try_files $uri $uri/ =404; | ||
add_header Content-Type "text/html; charset=utf-8"; | ||
} | ||
} |