Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions base-images/languages/go/1.24.13/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# These ARGs can be overridden at build time to customize the image
ARG REPO=labring-actions/devbox-base-images
ARG REGISTRY=ghcr.io
ARG L10N_NORMALIZED=en-us

# These ARGs are not recommended to be overridden at build time.
# Instead, update the Dockerfile directly for consistent builds,
# and release new versions as needed.
ARG OS_IMAGE_VERSION=v0.0.1-alpha.1-${L10N_NORMALIZED}

FROM ${REGISTRY}/${REPO}/debian-12.6:${OS_IMAGE_VERSION}
LABEL org.opencontainers.image.authors="The Devbox Authors"
# Add build script and execute it
COPY build.sh /build.sh
RUN chmod +x /build.sh && \
/build.sh && \
rm -f /build.sh
52 changes: 52 additions & 0 deletions base-images/languages/go/1.24.13/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -euo pipefail

L10N=${L10N:-en_US}
DEFAULT_DEVBOX_USER=${DEFAULT_DEVBOX_USER:-devbox}

# Install Go 1.24.13
RAW_ARCH="${TARGETARCH:-${ARCH:-$(dpkg --print-architecture)}}"
case "${RAW_ARCH}" in
amd64|x86_64) GO_ARCH=amd64 ;;
arm64|aarch64) GO_ARCH=arm64 ;;
*)
echo "Unsupported architecture: ${RAW_ARCH}" >&2
exit 1
;;
esac
GO_TARBALL="go1.24.13.linux-${GO_ARCH}.tar.gz"
curl -fsSLO "https://dl.google.com/go/${GO_TARBALL}" && \
rm -rf /usr/local/go && tar -C /usr/local -xzf "${GO_TARBALL}" && \
rm -f "${GO_TARBALL}"


# Set up Go for root
ROOT_HOME="${HOME:-/root}"
if [ "$L10N" = "zh_CN" ]; then
grep -qxF 'export GOPROXY=https://goproxy.cn,direct' "$ROOT_HOME/.bashrc" || \
echo 'export GOPROXY=https://goproxy.cn,direct' >> "$ROOT_HOME/.bashrc"
fi
mkdir -p "$ROOT_HOME/go/bin"
grep -qxF 'export GOPATH=$HOME/go' "$ROOT_HOME/.bashrc" || \
echo 'export GOPATH=$HOME/go' >> "$ROOT_HOME/.bashrc"
grep -qxF 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' "$ROOT_HOME/.bashrc" || \
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> "$ROOT_HOME/.bashrc"

# Set up Go for devbox user
DEVBOX_USER="${DEFAULT_DEVBOX_USER}"
DEVBOX_HOME="$(getent passwd "$DEVBOX_USER" | cut -d: -f6 || true)"
if [ -z "$DEVBOX_HOME" ]; then
DEVBOX_HOME="/home/${DEVBOX_USER}"
fi

if [ "$L10N" = "zh_CN" ]; then
grep -qxF 'export GOPROXY=https://goproxy.cn,direct' "$DEVBOX_HOME/.bashrc" 2>/dev/null || \
echo 'export GOPROXY=https://goproxy.cn,direct' >> "$DEVBOX_HOME/.bashrc"
fi
mkdir -p "$DEVBOX_HOME/go/bin"
chown -R "${DEVBOX_USER}:${DEVBOX_USER}" "$DEVBOX_HOME/go" || true

grep -qxF 'export GOPATH=$HOME/go' "$DEVBOX_HOME/.bashrc" 2>/dev/null || \
echo 'export GOPATH=$HOME/go' >> "$DEVBOX_HOME/.bashrc"
grep -qxF 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' "$DEVBOX_HOME/.bashrc" 2>/dev/null || \
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> "$DEVBOX_HOME/.bashrc"
17 changes: 17 additions & 0 deletions base-images/languages/go/1.25.9/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# These ARGs can be overridden at build time to customize the image
ARG REPO=labring-actions/devbox-base-images
ARG REGISTRY=ghcr.io
ARG L10N_NORMALIZED=en-us

# These ARGs are not recommended to be overridden at build time.
# Instead, update the Dockerfile directly for consistent builds,
# and release new versions as needed.
ARG OS_IMAGE_VERSION=v0.0.1-alpha.1-${L10N_NORMALIZED}

FROM ${REGISTRY}/${REPO}/debian-12.6:${OS_IMAGE_VERSION}
LABEL org.opencontainers.image.authors="The Devbox Authors"
# Add build script and execute it
COPY build.sh /build.sh
RUN chmod +x /build.sh && \
/build.sh && \
rm -f /build.sh
52 changes: 52 additions & 0 deletions base-images/languages/go/1.25.9/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -euo pipefail

L10N=${L10N:-en_US}
DEFAULT_DEVBOX_USER=${DEFAULT_DEVBOX_USER:-devbox}

# Install Go 1.25.9
RAW_ARCH="${TARGETARCH:-${ARCH:-$(dpkg --print-architecture)}}"
case "${RAW_ARCH}" in
amd64|x86_64) GO_ARCH=amd64 ;;
arm64|aarch64) GO_ARCH=arm64 ;;
*)
echo "Unsupported architecture: ${RAW_ARCH}" >&2
exit 1
;;
esac
GO_TARBALL="go1.25.9.linux-${GO_ARCH}.tar.gz"
curl -fsSLO "https://dl.google.com/go/${GO_TARBALL}" && \
rm -rf /usr/local/go && tar -C /usr/local -xzf "${GO_TARBALL}" && \
rm -f "${GO_TARBALL}"


# Set up Go for root
ROOT_HOME="${HOME:-/root}"
if [ "$L10N" = "zh_CN" ]; then
grep -qxF 'export GOPROXY=https://goproxy.cn,direct' "$ROOT_HOME/.bashrc" || \
echo 'export GOPROXY=https://goproxy.cn,direct' >> "$ROOT_HOME/.bashrc"
fi
mkdir -p "$ROOT_HOME/go/bin"
grep -qxF 'export GOPATH=$HOME/go' "$ROOT_HOME/.bashrc" || \
echo 'export GOPATH=$HOME/go' >> "$ROOT_HOME/.bashrc"
grep -qxF 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' "$ROOT_HOME/.bashrc" || \
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> "$ROOT_HOME/.bashrc"

# Set up Go for devbox user
DEVBOX_USER="${DEFAULT_DEVBOX_USER}"
DEVBOX_HOME="$(getent passwd "$DEVBOX_USER" | cut -d: -f6 || true)"
if [ -z "$DEVBOX_HOME" ]; then
DEVBOX_HOME="/home/${DEVBOX_USER}"
fi

if [ "$L10N" = "zh_CN" ]; then
grep -qxF 'export GOPROXY=https://goproxy.cn,direct' "$DEVBOX_HOME/.bashrc" 2>/dev/null || \
echo 'export GOPROXY=https://goproxy.cn,direct' >> "$DEVBOX_HOME/.bashrc"
fi
mkdir -p "$DEVBOX_HOME/go/bin"
chown -R "${DEVBOX_USER}:${DEVBOX_USER}" "$DEVBOX_HOME/go" || true

grep -qxF 'export GOPATH=$HOME/go' "$DEVBOX_HOME/.bashrc" 2>/dev/null || \
echo 'export GOPATH=$HOME/go' >> "$DEVBOX_HOME/.bashrc"
grep -qxF 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' "$DEVBOX_HOME/.bashrc" 2>/dev/null || \
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> "$DEVBOX_HOME/.bashrc"
21 changes: 21 additions & 0 deletions runtime-images/languages/go/1.24.13/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# These ARGs can be overridden at build time to customize the image
ARG REPO=labring-actions/devbox-base-images
ARG REGISTRY=ghcr.io
ARG L10N_NORMALIZED=en-us

# These ARGs are not recommended to be overridden at build time.
# Instead, update the Dockerfile directly for consistent builds,
# and release new versions as needed.
ARG RUNTIME_IMAGE_VERSION=v0.0.1-alpha.1-${L10N_NORMALIZED}

FROM ${REGISTRY}/${REPO}/go-1.24.13:${RUNTIME_IMAGE_VERSION}
LABEL org.opencontainers.image.authors="The Devbox Authors"
ENV PROJECT_TEMPLATE_DIR=/project-template
COPY ./project-template ${PROJECT_TEMPLATE_DIR}
COPY ./build.sh /build.sh
RUN chmod +x /build.sh && \
/build.sh && \
rm -f /build.sh && \
rm -rf ${PROJECT_TEMPLATE_DIR}
# Set the working directory to the default devbox user's project directory
WORKDIR /home/${DEFAULT_DEVBOX_USER}/project
44 changes: 44 additions & 0 deletions runtime-images/languages/go/1.24.13/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -euo pipefail

L10N=${L10N:-en_US}
DEFAULT_DEVBOX_USER=${DEFAULT_DEVBOX_USER:-devbox}
PROJECT_TEMPLATE_DIR=${PROJECT_TEMPLATE_DIR:-/project-template}

if ! id -u "$DEFAULT_DEVBOX_USER" &>/dev/null; then
echo "User $DEFAULT_DEVBOX_USER does not exist"
exit 1
fi

TARGET_DIR="/home/$DEFAULT_DEVBOX_USER/project"
mkdir -p "$TARGET_DIR"

if [ -f "$PROJECT_TEMPLATE_DIR/README.$L10N.md" ]; then
echo "README $PROJECT_TEMPLATE_DIR/README.$L10N.md exists. Copying to $TARGET_DIR/README.md"
cp "$PROJECT_TEMPLATE_DIR/README.$L10N.md" "$TARGET_DIR/README.md"
else
echo "README $PROJECT_TEMPLATE_DIR/README.$L10N.md does not exist. Skipping copy."
fi

DOCS_DIR=${DOCS_DIR:-/usr/share/devbox/docs}
if [ -f "$DOCS_DIR/README.s6-user-guide.$L10N.md" ]; then
cp "$DOCS_DIR/README.s6-user-guide.$L10N.md" "$TARGET_DIR/README.s6-user-guide.md"
elif [ -f "$DOCS_DIR/README.s6-user-guide.en_US.md" ]; then
cp "$DOCS_DIR/README.s6-user-guide.en_US.md" "$TARGET_DIR/README.s6-user-guide.md"
fi

# Copy project template contents (except localized readmes handled above).
# Using `/.` keeps hidden files/dirs if present.
cp -R "${PROJECT_TEMPLATE_DIR}/." "$TARGET_DIR/"

# If we wrote a localized README.md, remove the localized variants to keep the
# project dir clean (optional; safe if they don't exist).
rm -f "$TARGET_DIR/README.en_US.md" "$TARGET_DIR/README.zh_CN.md" || true

# Ensure entrypoint is executable if present.
if [ -f "$TARGET_DIR/entrypoint.sh" ]; then
chmod +x "$TARGET_DIR/entrypoint.sh"
fi

# Set ownership to default devbox user
chown -R "$DEFAULT_DEVBOX_USER:$DEFAULT_DEVBOX_USER" "$TARGET_DIR"
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Go 1.24.13 Runtime Template

This template provides a minimal Go HTTP service for DevBox runtime **Go 1.24.13**.

## Runtime Summary

- Language version: `Go 1.24.13`
- Base runtime image: `go-1.24.13`
- Entrypoint script: `entrypoint.sh`
- Default service port: `8080`

## Template Files

- `main.go`: HTTP server using `net/http`
- `entrypoint.sh`: mode-aware startup script

## Run in DevBox

Run commands from `/home/devbox/project`.

### Development mode

```bash
bash entrypoint.sh
```

Behavior:
- Runs `go run main.go` for fast iteration.

### Production mode

```bash
bash entrypoint.sh production
```

Behavior:
- Builds binary: `go build -o hello_world main.go`
- Runs binary: `./hello_world`

## Verify Service

```bash
curl http://127.0.0.1:8080
```

Expected output:

```text
Hello, World!
```

## Customization

- Add handlers/routes in `main.go`.
- Replace the single-file layout with a standard module structure when scaling.
- Keep the entrypoint build target aligned with your binary name.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Go 1.24.13 运行时模板

该模板为 DevBox **Go 1.24.13** 运行时提供一个最小可运行的 HTTP 服务。

## 运行时概览

- 语言版本:`Go 1.24.13`
- 基础运行时镜像:`go-1.24.13`
- 启动脚本:`entrypoint.sh`
- 默认服务端口:`8080`

## 模板文件

- `main.go`:基于 `net/http` 的 HTTP 服务
- `entrypoint.sh`:支持模式切换的启动脚本

## 在 DevBox 中运行

以下命令在 `/home/devbox/project` 目录执行。

### 开发模式

```bash
bash entrypoint.sh
```

行为说明:
- 使用 `go run main.go`,便于快速迭代。

### 生产模式

```bash
bash entrypoint.sh production
```

行为说明:
- 先构建二进制:`go build -o hello_world main.go`
- 再运行二进制:`./hello_world`

## 验证服务

```bash
curl http://127.0.0.1:8080
```

预期输出:

```text
Hello, World!
```

## 自定义建议

- 在 `main.go` 中增加路由与处理逻辑。
- 项目变大后可迁移为标准 Go module 目录结构。
- 若修改二进制名称,请同步更新 `entrypoint.sh` 的构建目标。
28 changes: 28 additions & 0 deletions runtime-images/languages/go/1.24.13/project-template/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
app_env=${1:-development}

# Define build target
build_target="hello_world"

# Development environment commands
dev_commands() {
echo "Running development environment commands..."
go run main.go
}

# Production environment commands
prod_commands() {
echo "Running production environment commands..."
go build -o $build_target main.go
./$build_target
}

# prod_commands
# Check environment variables to determine the running environment
if [ "$app_env" = "production" ] || [ "$app_env" = "prod" ] ; then
echo "Production environment detected"
prod_commands
else
echo "Development environment detected"
dev_commands
fi
16 changes: 16 additions & 0 deletions runtime-images/languages/go/1.24.13/project-template/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"fmt"
"net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, World!")
}

func main() {
http.HandleFunc("/", handler)
fmt.Println("Starting server on 0.0.0.0:8080")
http.ListenAndServe(":8080", nil)
}
21 changes: 21 additions & 0 deletions runtime-images/languages/go/1.25.9/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# These ARGs can be overridden at build time to customize the image
ARG REPO=labring-actions/devbox-base-images
ARG REGISTRY=ghcr.io
ARG L10N_NORMALIZED=en-us

# These ARGs are not recommended to be overridden at build time.
# Instead, update the Dockerfile directly for consistent builds,
# and release new versions as needed.
ARG RUNTIME_IMAGE_VERSION=v0.0.1-alpha.1-${L10N_NORMALIZED}

FROM ${REGISTRY}/${REPO}/go-1.25.9:${RUNTIME_IMAGE_VERSION}
LABEL org.opencontainers.image.authors="The Devbox Authors"
ENV PROJECT_TEMPLATE_DIR=/project-template
COPY ./project-template ${PROJECT_TEMPLATE_DIR}
COPY ./build.sh /build.sh
RUN chmod +x /build.sh && \
/build.sh && \
rm -f /build.sh && \
rm -rf ${PROJECT_TEMPLATE_DIR}
# Set the working directory to the default devbox user's project directory
WORKDIR /home/${DEFAULT_DEVBOX_USER}/project
Loading