Skip to content

Commit

Permalink
Merge pull request #13 from ministryofjustice/dep-updates
Browse files Browse the repository at this point in the history
Update and remove unused npm deps. Add prod docker-compose for local testing. Add access token
  • Loading branch information
EarthlingDavey authored Nov 26, 2024
2 parents f1a758b + 190f3bd commit b7b6150
Show file tree
Hide file tree
Showing 16 changed files with 978 additions and 7,466 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
!conf
conf/node/node_modules
!src
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
# AWS_CLOUDFRONT_PUBLIC_KEY_EXPIRING: "${{ secrets.AWS_CLOUDFRONT_PUBLIC_KEY_B }}"
BASIC_AUTH_USER: ${{ secrets.BASIC_AUTH_USER }}
BASIC_AUTH_PASS: ${{ secrets.BASIC_AUTH_PASS }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
run: |
## - - - - - - - - - -
## CloudFront - - - -
Expand Down
52 changes: 45 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM nginxinc/nginx-unprivileged
FROM nginxinc/nginx-unprivileged AS base

USER root

RUN apt-get update && apt-get -y install -qq libhttrack-dev httrack nodejs npm cron unzip curl
RUN apt-get update && \
apt-get -y install -qq \
libhttrack-dev httrack nodejs npm cron unzip curl

# Get AWS CLI V2
RUN set -eux; \
Expand All @@ -29,11 +31,9 @@ RUN set -eux; \
./aws/install; \
rm awscli.zip;

## nginx user uid=101
COPY --chown=101:101 conf/node /usr/local/bin

ARG user=archiver
ARG uid=1001

RUN addgroup --gid ${uid} ${user} && \
adduser --disabled-login --disabled-password --ingroup ${user} --home /${user} --gecos "${user} user" --shell /bin/bash --uid ${uid} ${user} && \
usermod -a -G ${user} nginx && \
Expand All @@ -42,10 +42,12 @@ RUN addgroup --gid ${uid} ${user} && \
echo "${user}" > /etc/cron.allow

COPY src/ /usr/share/nginx/html
COPY conf/node /usr/local/bin/node
COPY conf/nginx.conf /etc/nginx/conf.d/default.conf
COPY conf/entrypoint/ /docker-entrypoint.d
COPY conf/s3-sync.sh /usr/bin/s3sync
COPY conf/httrack /usr/local/bin/httrack
## -> Copy common entrypoint scripts (for both dev & prod images).
COPY conf/entrypoint/setup-credentials.sh conf/entrypoint/start-cron.sh /docker-entrypoint.d/

## -> make init scripts executable
RUN chmod -R +x /docker-entrypoint.d/ && \
Expand All @@ -62,6 +64,42 @@ RUN echo "*/10 * * * * /usr/bin/s3-sync >> /archiver/cron.log 2>&1" >> /etc/cron
RUN touch /${user}/cron.log && \
chmod 644 /${user}/cron.log

RUN apt remove -y unzip curl


# Create a development image, from the base image.
# The image is used for local development only.
FROM base AS dev

WORKDIR /usr/local/bin/node

COPY conf/entrypoint/start-node-dev.sh /docker-entrypoint.d/
RUN chmod -R +x /docker-entrypoint.d/start-node-dev.sh

RUN mkdir /usr/local/bin/node/node_modules && \
chown -R ${uid}:${uid} /usr/local/bin/node

ENV NODE_ENV=development

USER ${uid}



# Create a production image, from the base image.
# The image is used for deployment, and can be run locally.
FROM base AS build-prod

WORKDIR /usr/local/bin/node

COPY conf/entrypoint/start-node-prod.sh /docker-entrypoint.d/
RUN chmod -R +x /docker-entrypoint.d/start-node-prod.sh

# Install the node modules.
RUN npm ci

# Change the environment to production for runtime.
ENV NODE_ENV=production

# Remove the npm package manager.
RUN apt remove -y curl npm unzip

USER ${uid}
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ dory:
sync:
@docker compose exec spider s3sync

build:
bin/build.sh

launch: build
launch:
@bin/launch.sh
@echo "\n Intranet spider available here: http://spider.intranet.docker/\n"
@docker compose logs -f spider
Expand Down
7 changes: 0 additions & 7 deletions bin/build.sh

This file was deleted.

13 changes: 13 additions & 0 deletions conf/entrypoint/start-node-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

DOTS="\n \033[0;32m***\033[0m"

echo -e "${DOTS} ${DOTS} Grabbing dependencies for node... ${DOTS}\n"

# Install dependencies.
npm install

echo -e "${DOTS} ${DOTS} Running dev server ${DOTS}\n"

# Start the server in watch mode with the `dev` script.
npm run dev &
4 changes: 4 additions & 0 deletions conf/entrypoint/start-node-prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

nohup node /usr/local/bin/node/process.js &

4 changes: 0 additions & 4 deletions conf/entrypoint/start-node.sh

This file was deleted.

Loading

0 comments on commit b7b6150

Please sign in to comment.