Skip to content

Commit

Permalink
Merge pull request #18 from privacybydesign/dockerize
Browse files Browse the repository at this point in the history
Fixing bugs and improvements on the docker image
  • Loading branch information
saravahdatipour authored Jan 13, 2025
2 parents 83cfd2d + 9202745 commit c0e8072
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 95 deletions.
27 changes: 0 additions & 27 deletions .gitlab-ci.yml

This file was deleted.

60 changes: 37 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
FROM python:3.9-slim
# --- Stage 1 Node build
FROM node:18-slim AS node-build

WORKDIR /
WORKDIR /app

RUN apt-get update && \
apt-get install -y curl apache2 && \
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs && \
npm install -g yarn && \
pip install Jinja2 && \
pip install requests
COPY src ./
COPY webpack.config.js yarn.lock package.json ./

ENV NODE_OPTIONS=--openssl-legacy-provider
RUN yarn install --frozen-lockfile

ENV NODE_OPTIONS="--openssl-legacy-provider"
COPY . .
RUN python3 download_repos.py && \
python3 -u update.py && \
test -f index.json && \
yarn && yarn build && \
mkdir -p /var/www/html && \
cp -r /en /var/www/html/ && \
cp -r /nl /var/www/html/ && \
cp -r /repos /var/www/html/ && \
cp style.css /var/www/html/ && \
cp logo.svg /var/www/html/ && \
cp script.js /var/www/html/ && \
cp index.json /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 generate-index.py config.json ./
RUN ls -l /app

RUN pip install --no-cache-dir Jinja2 requests && \
python3 download_repos.py && \
python3 -u generate-index.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;"]
19 changes: 7 additions & 12 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Attribute index

Generate documentation for the IRMA scheme manager. You can browse a live
Generate documentation for the Yivi scheme manager. You can browse a live
version [over here](https://privacybydesign.foundation/attribute-index/en/).

## Installing
Expand All @@ -12,17 +12,15 @@ Dependencies:
* [Jinja2](http://jinja.pocoo.org/) (Debian package: `python3-jinja2`)
* yarn

Before generating content, download the scheme managers by running `download_repos.py`.
To add a scheme, configure the schemes config in `config.json`.

## Running

To generate the HTML for the attribute index, run the script:
Before you run the script to generate Yivi index pages run the `download_repos.py` script. This downloalds
most recent version of the schemes. If new schemes are added, you can modify the `config.json` file to add them.

python3 update.py
python3 download_repos.py
python3 generate-index.py

If you want to have an up-to-date attribute index, it is recommended to update
the scheme managers regularly and run the update script afterwards.

To generate the JavaScript handling issuance sessions of demo credentials, run:

Expand All @@ -31,12 +29,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:

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
File renamed without changes.
22 changes: 22 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server {
listen 80;
server_name _;
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";
}
location ~* \.(css|js|svg|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot)$ {
root /var/www/html;
try_files $uri =404;
access_log off;
expires max;
add_header Cache-Control "public";
}
}
69 changes: 36 additions & 33 deletions templates/credential-navigator.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,13 @@ <h2>Issuing Demo Credentials</h2>
</select>
</div>
<div class="col">
<select class="form-select mb-2" id="issuer">
<select class="form-select mb-2" id="issuer" disabled>
<option value="">Select Issuer</option>
{% if organized_data %}
{% for issuer in organized_data[0].issuers %}
<option value="{{ issuer.identifier }}">
{{ issuer.name[LANG] }}
</option>
{% endfor %}
{% endif %}
</select>
</div>
<div class="col">
<select class="form-select mb-2" id="credential">
<select class="form-select mb-2" id="credential" disabled>
<option value="">Select Credential</option>
{% if organized_data and organized_data[0].issuers %}
{% for credential in organized_data[0].issuers[0].credentials %}
<option value="{{ credential.identifier }}">
{{ credential.name[LANG] }}
</option>
{% endfor %}
{% endif %}
</select>
</div>
</div>
Expand All @@ -65,29 +51,46 @@ <h2>Issuing Demo Credentials</h2>

function updateIssuers(schemeId) {
const issuerSelect = document.getElementById('issuer');
const scheme = organizedData.find(s => s.identifier === schemeId);
const credentialSelect = document.getElementById('credential');

issuerSelect.innerHTML = '<option value="">Select Issuer</option>';
if (scheme) {
scheme.issuers.forEach(issuer => {
const option = new Option(issuer.name[{{LANG|tojson|safe}}], issuer.identifier);
issuerSelect.add(option);
});
credentialSelect.innerHTML = '<option value="">Select Credential</option>';
credentialSelect.disabled = true;

if (schemeId) {
const scheme = organizedData.find(s => s.identifier === schemeId);
if (scheme) {
scheme.issuers.forEach(issuer => {
const option = new Option(issuer.name[{{LANG|tojson|safe}}], issuer.identifier);
issuerSelect.add(option);
});
issuerSelect.disabled = false;
} else {
issuerSelect.disabled = true;
}
} else {
issuerSelect.disabled = true;
}
updateCredentials('', '');
}

function updateCredentials(schemeId, issuerId) {
const credentialSelect = document.getElementById('credential');
const scheme = organizedData.find(s => s.identifier === schemeId);
const issuer = scheme?.issuers.find(i => i.identifier === issuerId);


credentialSelect.innerHTML = '<option value="">Select Credential</option>';
if (issuer) {
issuer.credentials.forEach(cred => {
const option = new Option(cred.name[{{LANG|tojson|safe}}], cred.identifier);
credentialSelect.add(option);
});
if (schemeId && issuerId) {
const scheme = organizedData.find(s => s.identifier === schemeId);
const issuer = scheme?.issuers.find(i => i.identifier === issuerId);
if (issuer) {
issuer.credentials.forEach(cred => {
const option = new Option(cred.name[{{LANG|tojson|safe}}], cred.identifier);
credentialSelect.add(option);
});
credentialSelect.disabled = false;
} else {
credentialSelect.disabled = true;
}
} else {
credentialSelect.disabled = true;
}
}

Expand All @@ -107,4 +110,4 @@ <h2>Issuing Demo Credentials</h2>
});
</script>
</div>
{% endblock main %}
{% endblock main %}

0 comments on commit c0e8072

Please sign in to comment.