streamline the deployment process, and cleaning shit up!
This commit is contained in:
parent
ee07531ec2
commit
ea780a9835
12 changed files with 132 additions and 41 deletions
68
Dockerfile
68
Dockerfile
|
@ -1,15 +1,61 @@
|
|||
FROM node:21-alpine3.18
|
||||
# node image
|
||||
FROM node:21-alpine3.18 as compiled
|
||||
WORKDIR /tmp
|
||||
USER root
|
||||
|
||||
# Copy the source code into the temp folder.
|
||||
COPY . /tmp
|
||||
RUN yarn install --production
|
||||
RUN yarn global add typescript
|
||||
|
||||
# Installing the dependencies required for compiling.
|
||||
RUN yarn install && yarn global add typescript
|
||||
|
||||
# Compile the project FROM typescript INTO javascript
|
||||
RUN tsc
|
||||
RUN mkdir /app
|
||||
RUN cp -r /tmp/*.json /app
|
||||
RUN cp -r /tmp/build/src /app
|
||||
RUN cp -r /tmp/src/views /app/src/
|
||||
RUN cp -r /tmp/data.template/ /app/data.template
|
||||
RUN cp -r /tmp/node_modules /app
|
||||
COPY ./scripts/docker_run.sh /app/run.sh
|
||||
|
||||
# Putting some stuff into the final build
|
||||
RUN cp -r /tmp/*.json /tmp/build/ && \
|
||||
cp -r /tmp/data.template /tmp/build/ && \
|
||||
cp -r /tmp/src/views /tmp/build/src/ && \
|
||||
cp -r /tmp/data.template /tmp/build && \
|
||||
cp -r /tmp/scripts/docker_bootstrapper.sh /tmp/build/bootstrapper.sh && \
|
||||
cp -r /tmp/scripts/docker_run.sh /tmp/build/runner.sh
|
||||
|
||||
# The final version of disseminate is now in /tmp/build
|
||||
|
||||
FROM node:21-alpine3.18 as main_image
|
||||
|
||||
# Create a volume for our data folder
|
||||
VOLUME ["/app/data"]
|
||||
|
||||
# Create a directory for our new app.
|
||||
RUN mkdir -p /app
|
||||
|
||||
# Switch to the directory.
|
||||
WORKDIR /app
|
||||
CMD ["npm", "run", "docker:prod:run"]
|
||||
|
||||
# Delete default node user for the next step.
|
||||
RUN deluser node
|
||||
|
||||
# We want to run disseminate as a non-root user.
|
||||
ARG UID
|
||||
ARG GID
|
||||
RUN addgroup --gid $GID disseminate && \
|
||||
adduser --home /app --uid $UID -G disseminate --disabled-password disseminate
|
||||
|
||||
# Give our non-root user access to /app
|
||||
RUN chown -R disseminate:disseminate /app
|
||||
|
||||
# Installing bash, mostly for debugging.
|
||||
RUN apk add bash
|
||||
|
||||
# Switching to non-root user.
|
||||
USER disseminate
|
||||
|
||||
# Copying the compiled project into our main image, ownership of the build is set to our aforementioned (non-root) user.
|
||||
COPY --chown=$UID:$GID --from=compiled /tmp/build/ /app
|
||||
|
||||
# Installing the dependencies.
|
||||
RUN yarn install --production
|
||||
|
||||
# Startup command
|
||||
CMD ["npm", "run", "docker:prod:bootstrapper"]
|
||||
|
|
Reference in a new issue