Merge pull request 'CertAuthority' (#7) from CertAuthority into main

Reviewed-on: https://git.infra.nkode.tech/dkelly/go-nkode/pulls/7
This commit is contained in:
dkelly
2024-12-06 16:43:09 +00:00
6 changed files with 40 additions and 83 deletions

View File

@@ -19,16 +19,23 @@ RUN go mod download
COPY . .
# Build the application
RUN go build
RUN go build -o go-nkode ./cmd
# Stage 2: Runtime
FROM debian:bookworm-slim
# Install ca-certificates and update them
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates && \
update-ca-certificates && \
rm -rf /var/lib/apt/lists/*
#ENV FRONTEND_HOST=https://app.nkode.tech
#ENV FRONTEND_HOST=http://localhost:8090
ENV SVG_DIR=/app/data/icons
ENV DB_PATH=/app/data/sqlite/nkode.db
ENV SQLITE_DB=/app/data/sqlite/nkode.db
# Set the working directory inside the runtime container
WORKDIR /app

26
Taskfile.yaml Normal file
View File

@@ -0,0 +1,26 @@
version: "3"
vars:
compose_file: "./compose/local-compose.yaml"
cache_bust:
sh: "date +%s"
tasks:
build:
cmds:
- docker compose -f {{.compose_file}} build --no-cache
up:
cmds:
- docker compose -f {{.compose_file}} up
down:
cmds:
- docker compose -f {{.compose_file}} down
clean:
cmds:
- docker system prune -f
push:
cmds:
- docker buildx build --platform linux/amd64,linux/arm64 -t registry.infra.nkode.tech/go-nkode:latest --push .
exec:
cmds:
- docker exec -it cron-nkode bash

View File

@@ -1,7 +1,9 @@
services:
go-nkode:
container_name: go-nkode
image: registry.infra.nkode.tech/go-nkode
build:
context: ../
dockerfile: Dockerfile
volumes:
- /var/go-nkode/sqlite:/app/data/sqlite
- /var/go-nkode/icons:/app/data/icons
@@ -9,5 +11,8 @@ services:
environment:
- JWT_SECRET=0123456789
- FRONTEND_HOST=http://localhost:8090
- AWS_ACCESS_KEY_ID=AKIA5VCWLAGKV3RBVE7G
- AWS_REGION=us-east-1
- AWS_SECRET_ACCESS_KEY=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
ports:
- "8070:8080"

View File

@@ -1,80 +0,0 @@
#!/bin/bash
source ~/awscli-env/bin/activate
# Usage: ./backup_script.sh -l true or ./backup_script.sh -l false
# Parse command-line argument for local_db flag
while getopts "l:" opt; do
case $opt in
l)
LOCAL_DB=$OPTARG
;;
*)
echo "Usage: $0 -l [true|false]"
exit 1
;;
esac
done
# Validate LOCAL_DB argument
if [ "$LOCAL_DB" != "true" ] && [ "$LOCAL_DB" != "false" ]; then
echo "Error: Invalid value for -l. Must be 'true' or 'false'."
exit 1
fi
# Set the database path and backup destination based on LOCAL_DB value
if [ "$LOCAL_DB" = true ]; then
DB_PATH="/Users/donov/databases/nkode.db"
BACKUP_DIR="/var/tmp"
else
DB_PATH="/home/dkelly/database/nkode.db"
BACKUP_DIR="/var/tmp"
fi
BACKUP_NAME="backup_nkode_$(date +'%Y%m%d%H%M%S').tar.gz"
# Check if the database file exists
if [ ! -f "$DB_PATH" ]; then
echo "Error: Database file not found at $DB_PATH"
exit 1
fi
# Perform a WAL checkpoint to flush the WAL file to the main DB file
echo "Checkpointing WAL..."
sqlite3 "$DB_PATH" "PRAGMA wal_checkpoint(FULL);"
if [ $? -ne 0 ]; then
echo "Error: Failed to checkpoint WAL"
exit 1
fi
# Check if related files (.wal, .shm) exist
WAL_FILE="${DB_PATH}-wal"
SHM_FILE="${DB_PATH}-shm"
# Create a list of files to back up (main DB, WAL, and SHM if they exist)
FILES_TO_BACKUP=("$DB_PATH")
if [ -f "$WAL_FILE" ]; then
FILES_TO_BACKUP+=("$WAL_FILE")
fi
if [ -f "$SHM_FILE" ]; then
FILES_TO_BACKUP+=("$SHM_FILE")
fi
# Create a tar.gz archive of the database and related files
echo "Creating backup..."
tar -czf "$BACKUP_DIR/$BACKUP_NAME" "${FILES_TO_BACKUP[@]}"
if [ $? -eq 0 ]; then
echo "Backup successful: $BACKUP_DIR/$BACKUP_NAME"
else
echo "Error: Backup failed"
exit 1
fi
# Upload backup to S3
aws s3 cp "$BACKUP_DIR/$BACKUP_NAME" s3://nkode-db-backup
if [ $? -eq 0 ]; then
echo "Backup uploaded to S3 successfully."
else
echo "Error: Failed to upload backup to S3."
exit 1
fi

View File

@@ -1 +0,0 @@
docker buildx build --platform linux/amd64,linux/arm64 -t registry.infra.nkode.tech/go-nkode:latest --push .