From 9585718e0e1a6a58b919c59c716a2b7730ecd260 Mon Sep 17 00:00:00 2001 From: Kakious Date: Tue, 26 Sep 2023 15:03:01 -0400 Subject: [PATCH] chore: initial upload --- docker-images/backend-node.Dockerfile | 56 ++++ docker-images/backend-php.Dockerfile | 69 +++++ docker-images/main.Dockerfile | 33 +++ fox-api/main.tf | 259 ++++++++++++++++++ fox-api/nginx/nginx.conf | 53 ++++ fox-api/nginx/nginxconfig.io/general.conf | 32 +++ fox-api/nginx/nginxconfig.io/php_fastcgi.conf | 17 ++ fox-api/nginx/nginxconfig.io/security.conf | 13 + 8 files changed, 532 insertions(+) create mode 100644 docker-images/backend-node.Dockerfile create mode 100644 docker-images/backend-php.Dockerfile create mode 100644 docker-images/main.Dockerfile create mode 100644 fox-api/main.tf create mode 100644 fox-api/nginx/nginx.conf create mode 100644 fox-api/nginx/nginxconfig.io/general.conf create mode 100644 fox-api/nginx/nginxconfig.io/php_fastcgi.conf create mode 100644 fox-api/nginx/nginxconfig.io/security.conf diff --git a/docker-images/backend-node.Dockerfile b/docker-images/backend-node.Dockerfile new file mode 100644 index 0000000..127d9a2 --- /dev/null +++ b/docker-images/backend-node.Dockerfile @@ -0,0 +1,56 @@ +# Start from base image (built on Docker host) +FROM git.kakio.us/kakious/coder-base:latest + +# Install everything as root +USER root + +# Install Node +RUN curl -sL https://deb.nodesource.com/setup_19.x | bash - +RUN DEBIAN_FRONTEND="noninteractive" apt-get update -y && \ + apt-get install -y nodejs + +# Install Yarn +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +RUN DEBIAN_FRONTEND="noninteractive" apt-get update && apt-get install -y yarn + +# Create the persistent data folder +RUN mkdir -p /data + +# Install MySQL +RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y mysql-server + +# Move the data folder to the persistent data folder and grant mysql access to it +RUN mv /var/lib/mysql /data/mysql +RUN echo "datadir = /data/mysql" >> /etc/mysql/mysql.conf.d/mysqld.cnf +RUN usermod -a -G coder mysql + +# Create a symbolic link to the persistent data folder just in case +RUN ln -s /data/mysql /var/lib/mysql + +# Install Redis +RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y redis-server + +# Install the latest redisjson +RUN wget https://redismodules.s3.amazonaws.com/rejson/rejson.Linux-ubuntu20.04-x86_64.2.4.5.zip +RUN unzip rejson.Linux-ubuntu20.04-x86_64.2.4.5.zip +RUN mkdir -p /usr/lib/redis/modules +RUN cp rejson.so /usr/lib/redis/modules/rejson.so +RUN rm rejson.Linux-ubuntu20.04-x86_64.2.4.5.zip && rm rejson.so + +# Update the redis config to include loadmodule +RUN echo "loadmodule /usr/lib/redis/modules/rejson.so" >> /etc/redis/redis.conf + +# Install the latest rabbitmq +RUN apt install -y rabbitmq-server +RUN ln -s /data/rabbitmq /var/lib/rabbitmq + + + +RUN sudo usermod -d /data/mysql/ mysql + +# Make sure the services are started on the start of the container +CMD service mysql start && service redis-server start && service rabbitmq-server start && /usr/bin/code-server --bind-addr + +# Set back to coder user +USER coder \ No newline at end of file diff --git a/docker-images/backend-php.Dockerfile b/docker-images/backend-php.Dockerfile new file mode 100644 index 0000000..b7cf3cc --- /dev/null +++ b/docker-images/backend-php.Dockerfile @@ -0,0 +1,69 @@ +# Start from base image (built on Docker host) +FROM git.kakio.us/kakious/coder-base:latest + +# Install everything as root +USER root + +RUN DEBIAN_FRONTEND="noninteractive" apt-get update + +# Create the persistent data folder +RUN mkdir -p /data + +# Install MySQL +RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y mysql-server + +# Move the data folder to the persistent data folder and grant mysql access to it +RUN mv /var/lib/mysql /data/mysql +RUN echo "datadir = /data/mysql" >> /etc/mysql/mysql.conf.d/mysqld.cnf +RUN usermod -a -G coder mysql + +# Create a symbolic link to the persistent data folder just in case +RUN ln -s /data/mysql /var/lib/mysql + +# Install Redis +RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y redis-server + +# Install the latest redisjson +RUN wget https://redismodules.s3.amazonaws.com/rejson/rejson.Linux-ubuntu20.04-x86_64.2.4.5.zip +RUN unzip rejson.Linux-ubuntu20.04-x86_64.2.4.5.zip +RUN mkdir -p /usr/lib/redis/modules +RUN cp rejson.so /usr/lib/redis/modules/rejson.so +RUN rm rejson.Linux-ubuntu20.04-x86_64.2.4.5.zip && rm rejson.so + +# Update the redis config to include loadmodule +RUN echo "loadmodule /usr/lib/redis/modules/rejson.so" >> /etc/redis/redis.conf + +# Install the latest rabbitmq +RUN apt install -y rabbitmq-server +RUN ln -s /data/rabbitmq /var/lib/rabbitmq + +RUN sudo usermod -d /data/mysql/ mysql + + +RUN DEBIAN_FRONTEND="noninteractive" add-apt-repository ppa:ondrej/php -y +RUN DEBIAN_FRONTEND="noninteractive" apt-get update +RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y php8.2 php8.2-cli php8.2-bz2 php8.2-curl php8.2-mbstring php8.2-intl php8.2-apcu php8.2-redis php8.2-fpm + +# Install Composer +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + + +#Configure PHP-FPM +RUN sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/8.2/fpm/php.ini +RUN sed -i 's/;apc.enable_cli=0/apc.enable_cli=1/g' /etc/php/8.2/fpm/php.ini + +# Install NGINX +RUN DEBIAN_FRONTEND="noninteractive" apt-get install -y nginx + +# Setup Nginx config +RUN rm /etc/nginx/sites-enabled/default + +#Download nginx config from git +RUN wget https://raw.githubusercontent.com/kakious/coder/main/nginx.conf -O /etc/nginx/sites-enabled/default + + +# Make sure the services are started on the start of the container +CMD service mysql start && service redis-server start && service rabbitmq-server start && service php8.2-fpm start && service nginx start + +# Set back to coder user +USER coder \ No newline at end of file diff --git a/docker-images/main.Dockerfile b/docker-images/main.Dockerfile new file mode 100644 index 0000000..a688e92 --- /dev/null +++ b/docker-images/main.Dockerfile @@ -0,0 +1,33 @@ +FROM ubuntu:jammy + +RUN apt-get update && \ + DEBIAN_FRONTEND="noninteractive" apt-get install --yes \ + bash \ + build-essential \ + ca-certificates \ + curl \ + htop \ + locales \ + man \ + python3 \ + python3-pip \ + software-properties-common \ + sudo \ + systemd \ + systemd-sysv \ + unzip \ + vim \ + wget && \ + # Install latest Git using their official PPA + add-apt-repository ppa:git-core/ppa && \ + DEBIAN_FRONTEND="noninteractive" apt-get install --yes git + +# Add a user `coder` so that you're not developing as the `root` user +RUN useradd coder \ + --create-home \ + --shell=/bin/bash \ + --uid=1001 \ + --user-group && \ + echo "coder ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers.d/nopasswd + +USER coder \ No newline at end of file diff --git a/fox-api/main.tf b/fox-api/main.tf new file mode 100644 index 0000000..9040c14 --- /dev/null +++ b/fox-api/main.tf @@ -0,0 +1,259 @@ +terraform { + required_providers { + coder = { + source = "coder/coder" + version = "~> 0.8.3" + } + docker = { + source = "kreuzwerker/docker" + version = "~> 3.0.1" + } + } +} + +locals { + username = data.coder_workspace.me.owner +} + +data "coder_provisioner" "me" { +} + +provider "docker" { +} + +data "coder_workspace" "me" { +} + +data "coder_git_auth" "github" { + # Matches the ID of the git auth provider in Coder. + id = "primary-github" +} + +resource "coder_app" "fox_api" { + agent_id = coder_agent.main.id + slug = "fox-api" + display_name = "F.O.X. API" + icon = "https://media.furality.online/boop/furality.png" + url = "http://localhost:8080" + share = "public" + subdomain = false +} + +resource "coder_agent" "main" { + arch = data.coder_provisioner.me.arch + os = "linux" + + startup_script_timeout = 180 + startup_script = <<-EOT + set -e + + # start the services + echo "[SETUP] Starting core services (sql and redis)" + sudo service mysql start 2>&1 /dev/null + sudo service redis-server start 2>&1 /dev/null + echo "[SETUP] Core services started" + + if [ ! -f ~/.coder-env ]; then + echo "[SETUP] Creating ~/.coder-env" + echo "WORKSPACE_ENV=$WORKSPACE_ENV" >> ~/.coder-env + echo "USERNAME_ENV=$USERNAME_ENV" >> ~/.coder-env + echo "[SETUP] Created ~/.coder-env" + fi + + if [ ! -d ~/oauth-provider ]; then + echo "[SETUP] Cloning Github Repo" + git clone https://github.com/furality/oauth-provider/ + + echo "[SETUP] Git Keys imported" + + + echo "Downloading setup script from git" + wget -q -O ~/setup-script.sh https://git.kakio.us/kakious/docker-images/raw/branch/main/boop-keys/setup-fox.sh + echo "[SETUP] Downloaded setup script from git" + chmod +x ~/setup-script.sh + + echo "[SETUP] Running Setup Script" + sudo ./setup-script.sh 2>&1 /dev/null + echo "[SETUP] Setup Script Done" + cd ~/oauth-provider + fi + + echo "[SETUP] Setup Complete" + EOT + + env = { + GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}" + GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}" + GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}" + GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}" + GITHUB_TOKEN = "${data.coder_git_auth.github.access_token}" + WORKSPACE_ENV = "${data.coder_workspace.me.name}" + USERNAME_ENV = "${data.coder_workspace.me.owner}" + } + +metadata { + display_name = "RAM Usage" + key = "1_ram_usage" + script = "coder stat mem" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Home Disk" + key = "3_home_disk" + script = "coder stat disk --path $${HOME}" + interval = 60 + timeout = 1 + } + + metadata { + display_name = "CPU Usage (Host)" + key = "4_cpu_usage_host" + script = "coder stat cpu --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Memory Usage (Host)" + key = "5_mem_usage_host" + script = "coder stat mem --host" + interval = 10 + timeout = 1 + } + + metadata { + display_name = "Load Average (Host)" + key = "6_load_host" + # get load avg scaled by number of cores + script = <