streamline the deployment process, and cleaning shit up!

This commit is contained in:
hexlocation's laptop (asiago) 2024-03-30 16:33:59 -04:00
parent ee07531ec2
commit ea780a9835
12 changed files with 132 additions and 41 deletions

2
.gitignore vendored
View file

@ -130,6 +130,4 @@ dist
.yarn/install-state.gz .yarn/install-state.gz
.pnp.* .pnp.*
ignore ignore
posts
templates
data data

View file

@ -1,15 +1,61 @@
FROM node:21-alpine3.18 # node image
FROM node:21-alpine3.18 as compiled
WORKDIR /tmp WORKDIR /tmp
USER root
# Copy the source code into the temp folder.
COPY . /tmp 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 tsc
RUN mkdir /app
RUN cp -r /tmp/*.json /app # Putting some stuff into the final build
RUN cp -r /tmp/build/src /app RUN cp -r /tmp/*.json /tmp/build/ && \
RUN cp -r /tmp/src/views /app/src/ cp -r /tmp/data.template /tmp/build/ && \
RUN cp -r /tmp/data.template/ /app/data.template cp -r /tmp/src/views /tmp/build/src/ && \
RUN cp -r /tmp/node_modules /app cp -r /tmp/data.template /tmp/build && \
COPY ./scripts/docker_run.sh /app/run.sh 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 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"]

View file

@ -0,0 +1,3 @@
# About Me.
Hello!

View file

@ -0,0 +1,3 @@
# Contact Information.
Contact me!

View file

@ -0,0 +1,13 @@
# Welcome to Disseminate!
Welcome, user! We are glad to have you on board!
To start, find the "posts" directory in the data folder you have created, or mounted using docker.
This is the same directory you put your config file in.
Create a file named "hello.md", and start the file with:
```
# [Your Title]
```
Now you can start writing blog posts!

11
docker-compose.yml Normal file
View file

@ -0,0 +1,11 @@
services:
disseminate:
build:
context: .
args:
UID: 1000
GID: 1000
volumes:
- ./data:/app/data
ports:
- 3024:3024

View file

@ -14,8 +14,9 @@
"scripts":{ "scripts":{
"docker:build": "bash scripts/docker_build.sh", "docker:build": "bash scripts/docker_build.sh",
"docker:test": "bash scripts/docker_test.sh", "docker:test": "bash scripts/docker_test.sh",
"docker:test:bash": "bash scripts/docker_test_bash.sh", "docker:test:shell": "bash scripts/docker_test_bash.sh",
"docker:prod:run": "/bin/sh /app/run.sh", "docker:prod:bootstrapper": "/bin/bash /app/bootstrapper.sh",
"docker:prod:_runner": "/bin/bash /app/runner.sh",
"dev:run": "ts-node -r tsconfig-paths/register src/index.ts" "dev:run": "ts-node -r tsconfig-paths/register src/index.ts"
} }
} }

25
scripts/docker_bootstrapper.sh Executable file
View file

@ -0,0 +1,25 @@
cat << EOF
____ ______________ __
/ __ \/ _/ ___/ ___// / docker edition
/ / / // / \__ \\__ \/ / launching bootstrapper...
/ /_/ // / ___/ /__/ /_/ running as $(whoami)
/_____/___//____/____(_)
EOF
if [ -z "$(find data -mindepth 1 -maxdepth 1)" ]; then
echo '[bootstrapper] data directory is empty, copying template.'
cp -r data.template/* data/
chown -R disseminate:disseminate data/
fi
# echo "[bootstrapper] checking permissions for data folder"
# permissions=$(ls -ld data)
# ldArr=(${permissions// / })
#if [[ ${ldArr[3]} != "node" ]]; then
# echo "[bootstrapper] data folder is owned by user ${ldArr[3]}, which is not node."
# echo "[bootstrapper] correcting permissions..."
# chown -R 1000:1000 data/
#fi
echo "[bootstrapper] launching runner"
npm run docker:prod:_runner

View file

@ -1,4 +1,4 @@
# Disseminate Build Script # Disseminate Build Script
# This script builds disseminate into a docker container, using the dockerfile provided in the repository. # This script builds disseminate into a docker container, using the dockerfile provided in the repository.
docker build . -t disseminate:latest docker build --build-arg UID=1000 --build-arg GID=1000 . -t disseminate:latest

View file

@ -1,27 +1,14 @@
# I'm so bad at bash scripting # I'm so bad at bash scripting
cat << EOF #cat << EOF
____ ______________ __ # ____ ______________ __
/ __ \/ _/ ___/ ___// / # / __ \/ _/ ___/ ___// /
/ / / // / \__ \\__ \/ / # / / / // / \__ \\__ \/ /
/ /_/ // / ___/ /__/ /_/ # / /_/ // / ___/ /__/ /_/
/_____/___//____/____(_) #/_____/___//____/____(_)
#
#EOF
EOF echo '[runner] starting...'
if [ ! -d data ]; then
echo '-------------'
echo 'Data folder not found. Did you set up a volume?'
echo '-------------'
exit 1
fi
if [ -z "$(find data -mindepth 1 -maxdepth 1)" ]; then
echo '-------------'
echo 'Data directory is empty, copying template.'
echo '-------------'
cp -r data.template/* data/
fi
echo 'Starting...'
node src/index.js node src/index.js
echo 'Exiting...' echo '[runner] exited.'

View file

@ -1,5 +1,8 @@
# Disseminate docker test script # Disseminate docker test script
mkdir ignore mkdir ignore
cd ignore cd ignore
docker run --rm -it -p 3024:3024 -v ./data:/app/data disseminate:latest docker run --rm -it -p 3024:3024 -v ./data:/app/data disseminate:latest
cd ..
rm -R ignore

View file

@ -2,5 +2,6 @@
mkdir ignore mkdir ignore
cd ignore cd ignore
docker run --rm -it -p 3024:3024 -v ./data:/app/data disseminate:latest /bin/sh docker run --rm -it -p 3024:3024 --user 1000:1000 -v ./data:/app/data disseminate:latest /bin/bash
cd ..
rm ignore rm ignore