chore(Dockerfile): build and deploy via Docker, remove Nixpacks

This commit is contained in:
Cory Dransfeldt 2025-04-28 09:39:14 -07:00
parent f85f47bbd4
commit a4714a4790
No known key found for this signature in database
7 changed files with 73 additions and 19 deletions

7
.dockerignore Normal file
View file

@ -0,0 +1,7 @@
node_modules
npm-debug.log
.dockerignore
.git
.gitignore
Dockerfile
README.md

56
Dockerfile Normal file
View file

@ -0,0 +1,56 @@
FROM node:20-bullseye
# install system dependencies
RUN apt-get update && apt-get install -y \
git \
openssh-client \
rsync \
curl \
php-cli \
php-mbstring \
jq \
&& rm -rf /var/lib/apt/lists/*
# set working directory
WORKDIR /workdir
# build time args
ARG GIT_REPO
ARG GIT_BRANCH=main
# clone source
RUN git clone --depth 1 --branch ${GIT_BRANCH} ${GIT_REPO} app
# move into app directory
WORKDIR /workdir/app
# build-time env vars
ARG POSTGREST_API_KEY
ARG POSTGREST_URL
# export vars for build staps
ENV POSTGREST_API_KEY=${POSTGREST_API_KEY}
ENV POSTGREST_URL=${POSTGREST_URL}
# clean npm cache
RUN npm cache clean --force
# install deps
RUN npm install
# build
RUN npm run build
# set runtime env vars
ARG SERVER_IP
ENV SERVER_IP=${SERVER_IP}
# deploy and manage container healthcheck
CMD bash -c "\
mkdir -p ~/.ssh && \
echo \"${SSH_PRIVATE_KEY}\" > ~/.ssh/id_rsa && \
chmod 600 ~/.ssh/id_rsa && \
ssh-keyscan -H \"${SERVER_IP}\" >> ~/.ssh/known_hosts && \
rsync -avz --delete dist/ root@\"${SERVER_IP}\":/var/www/coryd.dev/ && \
echo \"✅ Deployed successfully\" && \
tail -f /dev/null"

View file

@ -45,4 +45,6 @@ NAVIDROME_API_TOKEN # server
ARTIST_IMPORT_TOKEN # server
COOLIFY_REBUILD_TOKEN # server
COOLIFY_REBUILD_URL # server
GIT_REPO # build
SERVER_URL # build
```

View file

@ -1,15 +0,0 @@
[phases.setup]
aptPkgs = [
"curl",
"wget",
"zip",
"unzip",
"php-cli",
"php-mbstring",
"openssh-client",
"rsync",
"jq"
]
cmds = [
"curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/bin/composer && chmod +x /usr/bin/composer",
]

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "coryd.dev",
"version": "3.3.4",
"version": "3.4.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "coryd.dev",
"version": "3.3.4",
"version": "3.4.0",
"license": "MIT",
"dependencies": {
"html-minifier-terser": "7.2.0",

View file

@ -1,6 +1,6 @@
{
"name": "coryd.dev",
"version": "3.3.4",
"version": "3.4.0",
"description": "The source for my personal site. Built using 11ty (and other tools).",
"type": "module",
"engines": {

View file

@ -30,7 +30,9 @@ SECRETS_JSON='{
"NAVIDROME_API_URL": "{{ op://Private/coryd.dev secrets/NAVIDROME_API_URL }}",
"NAVIDROME_API_TOKEN": "{{ op://Private/coryd.dev secrets/NAVIDROME_API_TOKEN }}",
"COOLIFY_REBUILD_TOKEN": "{{ op://Private/coryd.dev secrets/COOLIFY_REBUILD_TOKEN }}",
"COOLIFY_REBUILD_URL": "{{ op://Private/coryd.dev secrets/COOLIFY_REBUILD_URL }}"
"COOLIFY_REBUILD_URL": "{{ op://Private/coryd.dev secrets/COOLIFY_REBUILD_URL }}",
"GIT_REPO": "{{ op://Private/coryd.dev secrets/GIT_REPO }}",
"SERVER_IP": "{{ op://Private/coryd.dev secrets/SERVER_IP }}"
}'
SECRETS=$(echo "$SECRETS_JSON" | op inject)
@ -77,6 +79,8 @@ for file in scripts/templates/*.template; do
sed -i '' -e "s|{{NAVIDROME_API_TOKEN}}|$(escape_special_chars "$NAVIDROME_API_TOKEN")|g" "$new_file"
sed -i '' -e "s|{{COOLIFY_REBUILD_TOKEN}}|$(escape_special_chars "$COOLIFY_REBUILD_TOKEN")|g" "$new_file"
sed -i '' -e "s|{{COOLIFY_REBUILD_URL}}|$(escape_special_chars "$COOLIFY_REBUILD_URL")|g" "$new_file"
sed -i '' -e "s|{{GIT_REPO}}|$(escape_special_chars "$GIT_REPO")|g" "$new_file"
sed -i '' -e "s|{{SERVER_IP}}|$(escape_special_chars "$SERVER_IP")|g" "$new_file"
done
echo "${COLOR_BLUE}all configurations generated in the 'generated' folder.${COLOR_RESET}"