FROM nginx:latest

RUN apt-get update; apt-get install -y openssl
RUN apt-get install -y ca-certificates

RUN rm -rf /etc/nginx/conf.d/*;
COPY ./dist/default.conf /etc/nginx/conf.d/
COPY ./dist/nginx.conf /etc/nginx/

# Sets the arguments.
ARG BIN_NAME=nemt-portal-api
ARG APP_NAME=nemt-portal-api
ARG WORKDIR=/opt/app/

# Creates the necessary directories.
RUN mkdir -p /opt/app/docs
RUN mkdir -p /opt/app/certs
RUN mkdir -p /opt/app/static
RUN mkdir -p /var/log/bsbsi

# Copies the files to the container.
COPY ./dist/${BIN_NAME} /opt/app/${BIN_NAME}
ADD ./dist/docs/ /opt/app/docs/
ADD ./dist/certs/ /opt/app/certs/
ADD ./dist/static/ /opt/app/static/
ADD ./dist/config.toml /opt/app/config.toml
ADD ./dist/authorization_model.conf /opt/app/authorization_model.conf
ADD ./dist/authorization_policy.csv /opt/app/authorization_policy.csv

# Sets and executes the app.
WORKDIR /opt/app

EXPOSE 80
EXPOSE 443

CMD nginx & ./nemt-portal-api
