Skip to content

Commit

Permalink
multi-stage dockerfile and fix docker image bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
saravahdatipour committed Jan 13, 2025
1 parent f690787 commit 7067fe2
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 32 deletions.
68 changes: 41 additions & 27 deletions Dockerfile
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;"]
7 changes: 2 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ To generate the JavaScript handling issuance sessions of demo credentials, run:

## Running with Docker

To build and run the Docker container, build and run the docker image via the following:
To build and run the Docker container, you can use docker compose file

docker build -t attribute-index .
docker run -p 80:80 attribute-index

## Using untrusted scheme managers
docker compose up

Currently, scheme managers are considered trusted. Generating an attribute index
for an untrusted scheme manager has at least the following problems at the
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yaml
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
15 changes: 15 additions & 0 deletions nginx.conf
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";
}
}

0 comments on commit 7067fe2

Please sign in to comment.