From 631b6123969b95c441617848a207018b98f1d7ec Mon Sep 17 00:00:00 2001 From: phorcys420 <57866459+phorcys420@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:46:32 +0000 Subject: [PATCH] feat: add CTF image --- .../base/.devcontainer/Dockerfile | 79 --------------- .../supervisor/conf.d/code-server.conf | 5 - .../basic-env/supervisor/conf.d/vnc.conf | 15 --- .../basic-env/supervisor/logs/.gitkeep | 0 .../basic-env/supervisor/supervisord.conf | 21 ---- .../base/.devcontainer/devcontainer.json | 14 --- .../base/.devcontainer/user-dirs.dirs | 15 --- .../devcontainer/base/.devcontainer/xstartup | 9 -- .../ctf/.devcontainer/devcontainer.json | 16 +++ .../dart/.devcontainer/Dockerfile | 12 --- .../dart/.devcontainer/devcontainer.json | 9 -- .../java/.devcontainer/devcontainer.json | 12 --- .../.devcontainer/devcontainer.json | 13 --- .github/workflows/build-and-push-base.yml | 8 +- .github/workflows/build-and-push-others.yml | 18 ---- main.tf | 98 ++----------------- 16 files changed, 26 insertions(+), 318 deletions(-) delete mode 100644 .github/devcontainer/base/.devcontainer/Dockerfile delete mode 100644 .github/devcontainer/base/.devcontainer/basic-env/supervisor/conf.d/code-server.conf delete mode 100644 .github/devcontainer/base/.devcontainer/basic-env/supervisor/conf.d/vnc.conf delete mode 100644 .github/devcontainer/base/.devcontainer/basic-env/supervisor/logs/.gitkeep delete mode 100644 .github/devcontainer/base/.devcontainer/basic-env/supervisor/supervisord.conf delete mode 100644 .github/devcontainer/base/.devcontainer/devcontainer.json delete mode 100644 .github/devcontainer/base/.devcontainer/user-dirs.dirs delete mode 100644 .github/devcontainer/base/.devcontainer/xstartup create mode 100644 .github/devcontainer/ctf/.devcontainer/devcontainer.json delete mode 100644 .github/devcontainer/dart/.devcontainer/Dockerfile delete mode 100644 .github/devcontainer/dart/.devcontainer/devcontainer.json delete mode 100644 .github/devcontainer/java/.devcontainer/devcontainer.json delete mode 100644 .github/devcontainer/javascript/.devcontainer/devcontainer.json delete mode 100644 .github/workflows/build-and-push-others.yml diff --git a/.github/devcontainer/base/.devcontainer/Dockerfile b/.github/devcontainer/base/.devcontainer/Dockerfile deleted file mode 100644 index 0f5b971..0000000 --- a/.github/devcontainer/base/.devcontainer/Dockerfile +++ /dev/null @@ -1,79 +0,0 @@ -FROM ubuntu:latest - -USER root - -ENV DEBIAN_FRONTEND="noninteractive" -RUN apt update -y && \ - apt install -y --no-install-recommends ca-certificates apt-transport-https software-properties-common wget gpg - -# VSCode -RUN wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg && \ - install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg && \ - sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list' && \ - rm -f packages.microsoft.gpg - -# Basic tools -RUN apt update -y && \ - apt install -y \ - curl jq git \ - bash zsh \ - code code-insiders nano \ - sudo doas - -# Delete ubuntu user (because it's UID is 1000 and collides with the coder user, but we still want to comply with the codercom/enterprise-base:latest image) -RUN userdel ubuntu - -# Create coder user -RUN useradd coder --create-home --shell=/bin/bash --uid=1000 --user-group && \ - echo "coder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd && \ - echo "permit nopass coder as root" >> /etc/doas.conf - -# X11 + VNC -RUN apt install -y --no-install-recommends \ - xfonts-base xfonts-100dpi xfonts-scalable \ - dbus-x11 x11-xserver-utils x11-utils \ - xfwm4 xfdesktop4 xfconf libxfce4ui-utils \ - xfce4-panel xfce4-session \ - xfce4-settings xfce4-terminal thunar \ - psmisc xdg-utils \ - tigervnc-standalone-server tightvncpasswd \ - autocutsel websockify - -# Supervisor -RUN apt install supervisor - -ADD --chown=coder:coder --chmod=755 basic-env /usr/share/basic-env -WORKDIR /usr/share/basic-env - -RUN rm -rf /etc/supervisor && \ - ln -s /usr/share/basic-env/supervisor /etc/supervisor - -USER coder - -# noVNC -RUN git clone https://github.com/novnc/noVNC && \ - mv noVNC/vnc.html noVNC/index.html - -WORKDIR /home/coder - -# VNC -RUN mkdir .vnc && \ - touch .vnc/passwd && \ - chmod 600 .vnc/passwd && \ - touch .Xresources && \ - touch .Xauthority && \ - mkdir .user-dirs - -ADD --chown=coder:coder --chmod=700 xstartup /home/coder/.vnc/xstartup -ADD --chown=coder:coder user-dirs.dirs /home/coder/.config/user-dirs.dirs - -# Create a projects directory that way code-server doesn't have to spawn in the polluted mess that is /home/coder -RUN mkdir projects - -# Set default zshrc to avoid first use message -RUN cp /etc/zsh/newuser.zshrc.recommended $HOME/.zshrc - -# Extensions gallery for code-server (Microsoft instead of OpenVSIX -> for when you use coder/code-server) -ENV EXTENSIONS_GALLERY='{"serviceUrl":"https://marketplace.visualstudio.com/_apis/public/gallery","cacheUrl":"https://vscode.blob.core.windows.net/gallery/index","itemUrl":"https://marketplace.visualstudio.com/items","controlUrl":"","recommendationsUrl":""}' -ENV DEBIAN_FRONTEND="dialog" -ENV LANG="en_US.UTF-8" diff --git a/.github/devcontainer/base/.devcontainer/basic-env/supervisor/conf.d/code-server.conf b/.github/devcontainer/base/.devcontainer/basic-env/supervisor/conf.d/code-server.conf deleted file mode 100644 index c57244c..0000000 --- a/.github/devcontainer/base/.devcontainer/basic-env/supervisor/conf.d/code-server.conf +++ /dev/null @@ -1,5 +0,0 @@ -[program:code-server] -command=%(ENV_VSCODE_BINARY)s serve-web --accept-server-license-terms --without-connection-token -autorestart=unexpected -autostart=false -priority=1 diff --git a/.github/devcontainer/base/.devcontainer/basic-env/supervisor/conf.d/vnc.conf b/.github/devcontainer/base/.devcontainer/basic-env/supervisor/conf.d/vnc.conf deleted file mode 100644 index c751bcf..0000000 --- a/.github/devcontainer/base/.devcontainer/basic-env/supervisor/conf.d/vnc.conf +++ /dev/null @@ -1,15 +0,0 @@ -[program:vncserver] -command=vncserver -localhost -fg -geometry 1920x1080 -autorestart=unexpected -autostart=false -priority=5 - -[program:novnc] -command=websockify 8081 localhost:5901 --web /usr/share/basic-env/noVNC -autorestart=unexpected -autostart=false -priority=6 - -[group:vnc] -programs=vncserver,novnc -priority=2 diff --git a/.github/devcontainer/base/.devcontainer/basic-env/supervisor/logs/.gitkeep b/.github/devcontainer/base/.devcontainer/basic-env/supervisor/logs/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/.github/devcontainer/base/.devcontainer/basic-env/supervisor/supervisord.conf b/.github/devcontainer/base/.devcontainer/basic-env/supervisor/supervisord.conf deleted file mode 100644 index 429ebcf..0000000 --- a/.github/devcontainer/base/.devcontainer/basic-env/supervisor/supervisord.conf +++ /dev/null @@ -1,21 +0,0 @@ -[supervisord] -logfile=%(ENV_SUPERVISOR_DIR)s/logs/supervisord.log -childlogdir=%(ENV_SUPERVISOR_DIR)s/logs - -pidfile=%(ENV_SUPERVISOR_DIR)s/supervisord.pid - -[supervisorctl] -serverurl=unix:///%(ENV_SUPERVISOR_DIR)s/supervisor.sock - -[unix_http_server] -file=%(ENV_SUPERVISOR_DIR)s/supervisor.sock -chmod=0700 - -[inet_http_server] -port=8079 - -[rpcinterface:supervisor] -supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface - -[include] -files = %(ENV_SUPERVISOR_DIR)s/supervisord.base.conf %(ENV_SUPERVISOR_DIR)s/conf.d/*.conf diff --git a/.github/devcontainer/base/.devcontainer/devcontainer.json b/.github/devcontainer/base/.devcontainer/devcontainer.json deleted file mode 100644 index 9309afa..0000000 --- a/.github/devcontainer/base/.devcontainer/devcontainer.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "uwu/basic-env - Base", - - "build": { - "dockerfile": "Dockerfile" - }, - - "features": { - "ghcr.io/devcontainers/features/docker-in-docker:2": {}, - "ghcr.io/devcontainers/features/github-cli:1": {} - }, - - "remoteUser": "coder" -} diff --git a/.github/devcontainer/base/.devcontainer/user-dirs.dirs b/.github/devcontainer/base/.devcontainer/user-dirs.dirs deleted file mode 100644 index c57e9ef..0000000 --- a/.github/devcontainer/base/.devcontainer/user-dirs.dirs +++ /dev/null @@ -1,15 +0,0 @@ -# This file is written by xdg-user-dirs-update -# If you want to change or add directories, just edit the line you're -# interested in. All local changes will be retained on the next run. -# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped -# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an -# absolute path. No other format is supported. -# -XDG_DESKTOP_DIR="$HOME/.user-dirs/Desktop" -XDG_DOWNLOAD_DIR="$HOME/.user-dirs/Downloads" -XDG_TEMPLATES_DIR="$HOME/.user-dirs/Templates" -XDG_PUBLICSHARE_DIR="$HOME/.user-dirs/Public" -XDG_DOCUMENTS_DIR="$HOME/.user-dirs/Documents" -XDG_MUSIC_DIR="$HOME/.user-dirs/Music" -XDG_PICTURES_DIR="$HOME/.user-dirs/Pictures" -XDG_VIDEOS_DIR="$HOME/.user-dirs/Videos" diff --git a/.github/devcontainer/base/.devcontainer/xstartup b/.github/devcontainer/base/.devcontainer/xstartup deleted file mode 100644 index 41b4316..0000000 --- a/.github/devcontainer/base/.devcontainer/xstartup +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -xrdb "$HOME/.Xresources" -xsetroot -solid grey - -# Clipboard sharing -autocutsel -fork - -export XKL_XMODMAP_DISABLE=1 -/etc/X11/Xsession diff --git a/.github/devcontainer/ctf/.devcontainer/devcontainer.json b/.github/devcontainer/ctf/.devcontainer/devcontainer.json new file mode 100644 index 0000000..64ed2d0 --- /dev/null +++ b/.github/devcontainer/ctf/.devcontainer/devcontainer.json @@ -0,0 +1,16 @@ +{ + "image": "ghcr.io/uwu/basic-env/base:latest", + + "features": { + "ghcr.io/devcontainers/features/python:1": {}, + "ghcr.io/devcontainers/features/node:1": { + "nodeGypDependencies": false, + "installYarnUsingApt": false + }, + + "ghcr.io/phorcys420/devcontainer-features/burp-suite:latest": {}, + + "ghcr.io/phorcys420/devcontainer-features/ghidra:latest": {}, + "ghcr.io/phorcys420/devcontainer-features/cutter:latest": {} + } +} \ No newline at end of file diff --git a/.github/devcontainer/dart/.devcontainer/Dockerfile b/.github/devcontainer/dart/.devcontainer/Dockerfile deleted file mode 100644 index 125c15b..0000000 --- a/.github/devcontainer/dart/.devcontainer/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM ghcr.io/uwu/basic-env/base:latest - -USER root - -ENV DEBIAN_FRONTEND="noninteractive" -RUN wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/dart.gpg && \ - echo "deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main" > /etc/apt/sources.list.d/dart_stable.list && \ - apt update -y && \ - apt install -y dart - -USER coder -ENV DEBIAN_FRONTEND="dialog" \ No newline at end of file diff --git a/.github/devcontainer/dart/.devcontainer/devcontainer.json b/.github/devcontainer/dart/.devcontainer/devcontainer.json deleted file mode 100644 index 9844d0b..0000000 --- a/.github/devcontainer/dart/.devcontainer/devcontainer.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "uwu/basic-env - Dart", - - "build": { - "dockerfile": "Dockerfile" - }, - - "remoteUser": "coder" -} \ No newline at end of file diff --git a/.github/devcontainer/java/.devcontainer/devcontainer.json b/.github/devcontainer/java/.devcontainer/devcontainer.json deleted file mode 100644 index f9bb9e6..0000000 --- a/.github/devcontainer/java/.devcontainer/devcontainer.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "uwu/basic-env - Java", - "image": "ghcr.io/uwu/basic-env/base:latest", - - "features": { - "ghcr.io/devcontainers/features/java:1": { - "jdkDistro": "tem" - } - }, - - "remoteUser": "coder" -} \ No newline at end of file diff --git a/.github/devcontainer/javascript/.devcontainer/devcontainer.json b/.github/devcontainer/javascript/.devcontainer/devcontainer.json deleted file mode 100644 index 14c6e04..0000000 --- a/.github/devcontainer/javascript/.devcontainer/devcontainer.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "uwu/basic-env - JavaScript", - "image": "ghcr.io/uwu/basic-env/base:latest", - - "features": { - "ghcr.io/devcontainers/features/node:1": { - "version": "lts", - "installYarnUsingApt": false - } - }, - - "remoteUser": "coder" -} \ No newline at end of file diff --git a/.github/workflows/build-and-push-base.yml b/.github/workflows/build-and-push-base.yml index 3a6b7c5..a47c888 100644 --- a/.github/workflows/build-and-push-base.yml +++ b/.github/workflows/build-and-push-base.yml @@ -5,12 +5,12 @@ on: push: branches: - "main" - pull_requests: - branches: - - "main" + pull_request: + branches: + - "main" jobs: build: uses: uwu/basic-env/.github/workflows/_build-and-push.yml@main with: - image: base \ No newline at end of file + image: ctf \ No newline at end of file diff --git a/.github/workflows/build-and-push-others.yml b/.github/workflows/build-and-push-others.yml deleted file mode 100644 index a47ace5..0000000 --- a/.github/workflows/build-and-push-others.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Build & push other images - -on: - workflow_dispatch: - workflow_run: - workflows: ["Build & push base image"] - branches: [main] - types: - - completed - -jobs: - build: - uses: uwu/basic-env/.github/workflows/_build-and-push.yml@main - strategy: - matrix: - image: [dart, java, javascript] - with: - image: ${{ matrix.image }} \ No newline at end of file diff --git a/main.tf b/main.tf index 914c209..99bce55 100644 --- a/main.tf +++ b/main.tf @@ -17,12 +17,6 @@ locals { workspace_name = lower(data.coder_workspace.me.name) user_name = lower(data.coder_workspace.me.owner) - - images = { - javascript = docker_image.javascript_image - dart = docker_image.dart_image - java = docker_image.java_image - } } provider "docker" { @@ -92,38 +86,6 @@ fi EOT } -data "coder_parameter" "docker_image" { - name = "Docker Image" - description = "Which Docker image do you want to use?" - - type = "string" - default = "javascript" - - order = 1 - - mutable = true - - option { - name = "JavaScript" - value = "javascript" - } - - option { - name = "Dart" - value = "dart" - } - - option { - name = "Java" - value = "java" - } - - option { - name = "Base" - value = "base" - } -} - data "coder_parameter" "shell" { name = "Shell" description = "Which shell do you want to be your default shell?" @@ -309,75 +271,27 @@ resource "coder_metadata" "home" { } } -resource "docker_image" "javascript_image" { - count = data.coder_parameter.docker_image.value == "javascript" ? 1 : 0 - - name = "ghcr.io/uwu/basic-env/javascript:latest" - - keep_locally = true -} - -resource "docker_image" "dart_image" { - count = data.coder_parameter.docker_image.value == "dart" ? 1 : 0 - - name = "ghcr.io/uwu/basic-env/dart:latest" - - keep_locally = true -} - -resource "docker_image" "java_image" { - count = data.coder_parameter.docker_image.value == "java" ? 1 : 0 - - name = "ghcr.io/uwu/basic-env/java:latest" +resource "docker_image" "ctf_image" { + name = "ghcr.io/phorcys420/ctf-env:latest" keep_locally = true } -resource "coder_metadata" "javascript_image" { - count = data.coder_parameter.docker_image.value == "javascript" ? 1 : 0 - - resource_id = docker_image.javascript_image[0].id - - hide = true - - item { - key = "description" - value = "JavaScript container image" - } -} - -resource "coder_metadata" "dart_image" { - count = data.coder_parameter.docker_image.value == "dart" ? 1 : 0 - - resource_id = docker_image.dart_image[0].id - - hide = true - - item { - key = "description" - value = "Dart container image" - } -} - -resource "coder_metadata" "java_image" { - count = data.coder_parameter.docker_image.value == "java" ? 1 : 0 - - resource_id = docker_image.java_image[0].id +resource "coder_metadata" "ctf_image" { + resource_id = docker_image.ctf_image.id hide = true item { key = "description" - value = "Java container image" + value = "Docker image" } } resource "docker_container" "workspace" { count = data.coder_workspace.me.start_count - # we need to define a relation table in locals because we can't simply access resources like this: docker_image["javascript_image"] - # we need to access [0] because we define a count in the docker_image's definition - image = local.images[data.coder_parameter.docker_image.value][0].image_id + image = docker_image.ctf_image.image_id name = "coder-${local.user_name}-${local.workspace_name}" hostname = local.workspace_name