-
Notifications
You must be signed in to change notification settings - Fork 11
Dockerize beast #455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bl4ze/dev
Are you sure you want to change the base?
Dockerize beast #455
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| FROM golang:1.23 AS builder | ||
|
|
||
| RUN apt-get update && apt-get install -y \ | ||
| make git gcc util-linux \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
|
|
||
| COPY . . | ||
|
|
||
| RUN cp scripts/docker-enter /usr/bin/docker-enter && \ | ||
| cp scripts/docker_enter /usr/bin/docker_enter && \ | ||
| chmod u+s /usr/bin/docker_enter && \ | ||
| gcc -o /usr/bin/importenv scripts/importenv.c | ||
|
|
||
| RUN make build | ||
|
|
||
| FROM ubuntu:22.04 | ||
|
|
||
| RUN apt-get update && apt-get install -y ca-certificates \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| COPY --from=builder /go/bin/beast /usr/local/bin/beast | ||
| COPY setup.sh /usr/local/bin/setup.sh | ||
| RUN chmod +x /usr/local/bin/setup.sh | ||
|
|
||
| EXPOSE 5005 | ||
|
|
||
| ENTRYPOINT ["setup.sh"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,3 +81,66 @@ installenv: | |
| @./scripts/installenv.sh | ||
|
|
||
| .PHONY: build format test check_format tools docs installenv | ||
|
|
||
| # ── Docker Compose Targets ──────────────────────────────────────────────────── | ||
| # Usage: make up NAME=myctf | ||
| # | ||
| # NAME (required, no spaces) — used to create a .<NAME> folder on the host which | ||
| # is mounted as /root/.beast inside the beast container. This keeps each | ||
| # deployment isolated and named. | ||
| # | ||
| # Prerequisites: | ||
| # - config.toml must exist alongside this Makefile. | ||
| # - In config.toml set psql_config.host = "postgres" (the compose service name). | ||
| # | ||
|
Comment on lines
+92
to
+95
|
||
| # Targets: | ||
| # make up NAME=<name> — set up .<name>/, copy config, start services | ||
| # make down NAME=<name> — stop and remove services | ||
| # make logs NAME=<name> — tail beast service logs | ||
|
|
||
| check-name: | ||
| @if [ -z "$(NAME)" ]; then \ | ||
| echo "Error: NAME is required. Usage: make up NAME=myctf"; \ | ||
| exit 1; \ | ||
| fi | ||
| @if echo "$(NAME)" | grep -q "[[:space:]]"; then \ | ||
| echo "Error: NAME must not contain spaces"; \ | ||
| exit 1; \ | ||
| fi | ||
|
|
||
| check-config: | ||
| @if [ ! -f "config.toml" ]; then \ | ||
| echo "Error: config.toml not found in current directory."; \ | ||
| echo "Place your config.toml here (see _examples/example.config.toml)."; \ | ||
| echo "Ensure psql_config.host = \"postgres\" for the compose network."; \ | ||
| exit 1; \ | ||
| fi | ||
|
|
||
| BEAST_DIR = $(HOME)/.$(NAME) | ||
|
|
||
| setup-beast-dir: check-name check-config | ||
| @echo "[*] Setting up $(BEAST_DIR)..." | ||
| @mkdir -p $(BEAST_DIR)/assets/logo | ||
| @mkdir -p $(BEAST_DIR)/assets/mailTemplates | ||
| @mkdir -p $(BEAST_DIR)/remote | ||
| @mkdir -p $(BEAST_DIR)/uploads | ||
| @mkdir -p $(BEAST_DIR)/secrets | ||
| @mkdir -p $(BEAST_DIR)/scripts | ||
| @mkdir -p $(BEAST_DIR)/staging | ||
| @mkdir -p $(BEAST_DIR)/cache | ||
| @mkdir -p $(BEAST_DIR)/logs | ||
| @cp config.toml $(BEAST_DIR)/config.toml | ||
| @echo "[*] $(BEAST_DIR) ready (mounted as /root/.beast in container)" | ||
|
|
||
| up: setup-beast-dir | ||
| @echo "[*] Starting beast services (project: $(NAME))..." | ||
| @BEAST_DIR=$(BEAST_DIR) docker compose --project-name $(NAME) up -d --build | ||
| @echo "[*] Beast API running at http://localhost:5005" | ||
|
|
||
| down: check-name | ||
| @docker compose --project-name $(NAME) down | ||
|
|
||
| logs: check-name | ||
| @docker compose --project-name $(NAME) logs -f beast | ||
|
|
||
| .PHONY: check-name check-config setup-beast-dir up down logs | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,14 +50,14 @@ func DeployStaticContentContainer() error { | |
|
|
||
| // Remove the prefix sha256: | ||
| imageId := images[0].ID[7:] | ||
| stagingDirPath := filepath.Join(core.BEAST_GLOBAL_DIR, core.BEAST_STAGING_DIR) | ||
| stagingDirPath := filepath.Join(core.BEAST_MOUNT_DIR, core.BEAST_STAGING_DIR) | ||
| err = utils.CreateIfNotExistDir(stagingDirPath) | ||
| if err != nil { | ||
| log.Errorf("Error in validating staging mount point : %s", err) | ||
| return errors.New("INVALID_STAGING_AREA") | ||
| } | ||
|
|
||
| beastStaticAuthFile := filepath.Join(core.BEAST_GLOBAL_DIR, core.BEAST_STATIC_AUTH_FILE) | ||
| beastStaticAuthFile := filepath.Join(core.BEAST_MOUNT_DIR, core.BEAST_STATIC_AUTH_FILE) | ||
| err = utils.ValidateFileExists(beastStaticAuthFile) | ||
|
Comment on lines
+53
to
61
|
||
| if err != nil { | ||
| p := fmt.Errorf("BEAST STATIC: Authentication file does not exist for beast static container, cannot proceed deployment") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| services: | ||
| beast: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile.app | ||
| network_mode: host | ||
| volumes: | ||
| - ${BEAST_DIR}:/root/.beast | ||
| - /var/run/docker.sock:/var/run/docker.sock | ||
| environment: | ||
| - HOME=/root | ||
| - BEAST_FLAGS=${BEAST_FLAGS:--v} | ||
| - BEAST_HOST_DIR=${BEAST_DIR} | ||
| restart: unless-stopped | ||
|
Comment on lines
+7
to
+14
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,35 +1,77 @@ | ||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Detect if running inside a Docker container | ||||||||||||||||||||||||||||||||||||||||
| IN_CONTAINER=false | ||||||||||||||||||||||||||||||||||||||||
| [ -f /.dockerenv ] && IN_CONTAINER=true | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| echo -e "Setting up sample environment for beast..." | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # In container, HOME=/root; locally, use /home/$USER | ||||||||||||||||||||||||||||||||||||||||
| if [ "$IN_CONTAINER" = true ]; then | ||||||||||||||||||||||||||||||||||||||||
| BEAST_HOME="$HOME" | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| BEAST_HOME="/home/$USER" | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+13
|
||||||||||||||||||||||||||||||||||||||||
| # In container, HOME=/root; locally, use /home/$USER | |
| if [ "$IN_CONTAINER" = true ]; then | |
| BEAST_HOME="$HOME" | |
| else | |
| BEAST_HOME="/home/$USER" | |
| # Determine BEAST_HOME: allow override, prefer HOME, fall back to /home/$USER | |
| if [ -n "$BEAST_HOME" ]; then | |
| : | |
| elif [ "$IN_CONTAINER" = true ]; then | |
| BEAST_HOME="${HOME:-/root}" | |
| else | |
| if [ -n "$HOME" ]; then | |
| BEAST_HOME="$HOME" | |
| elif [ -n "$USER" ]; then | |
| BEAST_HOME="/home/$USER" | |
| else | |
| echo "Unable to determine BEAST_HOME; set BEAST_HOME or HOME." >&2 | |
| exit 1 | |
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The runtime image doesn’t install the
dockerCLI / Compose plugin, but the app callsexec.Command("docker", "compose", ...)(see pkg/cr/containers.go). In the container this will fail withdocker: not foundfor Docker Compose-based challenge deployments; install a docker CLI + compose plugin in the final stage (or refactor to avoid shelling out).