created deploy site shell script and made sure i am actually loading the api key from .env

This commit is contained in:
someone 2025-12-07 22:31:32 +01:00
parent 1c475e270e
commit 4a2490a443
3 changed files with 45 additions and 0 deletions

View File

@ -17,6 +17,7 @@ yarn-error.log*
pnpm-debug.log*
# Local env files
.env
.env.local
.env.development.local
.env.test.local

View File

@ -2,6 +2,9 @@
FROM oven/bun:1 as builder
WORKDIR /app
# Declare build argument for the API key
ARG VITE_GPT_OSS_API_KEY
# Copy configuration files and install dependencies
# This layer is cached to speed up future builds
COPY package.json bun.lockb ./
@ -9,6 +12,9 @@ COPY tsconfig.json tsconfig.node.json ./
COPY vite.config.ts postcss.config.js tailwind.config.ts ./
RUN bun install --frozen-lockfile
# Set it as an environment variable for Vite to pick up during build
ENV VITE_GPT_OSS_API_KEY=$VITE_GPT_OSS_API_KEY
# Copy the rest of the source code
COPY . .

38
deploy-site.sh Normal file
View File

@ -0,0 +1,38 @@
#!/bin/bash
set -e
# Load environment variables from .env file
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
fi
# Force-remove frozen-lockfile from Dockerfile (every time, just in case)
sed -i 's/bun install --frozen-lockfile/bun install/' Dockerfile 2>/dev/null || true
# If bun.lockb is missing or broken → delete it so bun install regenerates it
[ -f bun.lockb ] && ! grep -q "lockfileVersion" bun.lockb 2>/dev/null && rm -f bun.lockb
echo "Building your site (this will work now)..."
docker build --target builder --no-cache -t own-site-builder \
--build-arg VITE_GPT_OSS_API_KEY="${VITE_GPT_OSS_API_KEY}" .
echo "Deploying fresh build..."
docker create --name tmp-deploy own-site-builder
rm -rf ~/caddy/site/jory/*
mkdir -p ~/caddy/site/jory
docker cp tmp-deploy:/app/dist/. ~/caddy/site/jory/
# Favicon guaranteed
cp -f favicon.gif ~/caddy/site/jory/ 2>/dev/null || echo "No favicon.gif skipped"
# Cleanup
docker rm tmp-deploy
docker rmi own-site-builder
# Restart Caddy
docker restart caddy
echo ""
echo "DEPLOYED 100% SUCCESSFULLY"
echo "Site + favicon live now"