2 commited on
Commit
3ab24da
·
1 Parent(s): 89f40dc

chore: 更新Docker配置并添加部署脚本

Browse files

• 优化Dockerfile构建步骤
• 新增entrypoint.sh启动脚本
• 添加99-custom-setup.sh初始化脚本

Files changed (4) hide show
  1. 99-custom-setup.sh +44 -0
  2. Dockerfile +24 -65
  3. Dockerfile.bak +25 -0
  4. entrypoint.sh +74 -0
99-custom-setup.sh ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/command/with-contenv bash
2
+ # This script is executed by S6 overlay during container initialization.
3
+ set -e
4
+
5
+ echo "[custom-setup] Starting custom setup script (99-custom-setup.sh)..."
6
+
7
+ # Attempt to install VS Code extensions
8
+ # The user for linuxserver.io images is typically 'abc' (PUID/PGID 1000/1000)
9
+ # Extensions are installed into the user's data directory, usually within /config
10
+
11
+ EXTENSIONS_TO_INSTALL=(
12
+ "ms-python.python" # Python extension by Microsoft
13
+ "dbaeumer.vscode-eslint" # ESLint extension
14
+ )
15
+
16
+ # Check if openvscode-server or code-server command is available and try to install extensions
17
+ # It's important to run this as the correct user (abc)
18
+ INSTALL_CMD=""
19
+ if command -v openvscode-server &> /dev/null; then
20
+ INSTALL_CMD="openvscode-server"
21
+ elif command -v code-server &> /dev/null; then
22
+ INSTALL_CMD="code-server"
23
+ fi
24
+
25
+ if [ -n "$INSTALL_CMD" ]; then
26
+ echo "[custom-setup] Found command: $INSTALL_CMD. Attempting to install extensions..."
27
+ for EXT_ID in "${EXTENSIONS_TO_INSTALL[@]}"; do
28
+ echo "[custom-setup] Installing extension: $EXT_ID"
29
+ if su -ls /bin/bash abc -c "$INSTALL_CMD --install-extension $EXT_ID --force"; then
30
+ echo "[custom-setup] Successfully installed $EXT_ID (or it was already installed)."
31
+ else
32
+ echo "[custom-setup] WARN: Failed to install extension $EXT_ID. Please try installing it manually from the VS Code UI."
33
+ fi
34
+ done
35
+ else
36
+ echo "[custom-setup] WARN: Neither 'openvscode-server' nor 'code-server' command found in PATH. Skipping automatic extension installation."
37
+ fi
38
+
39
+ echo "[custom-setup] Extension installation process finished."
40
+
41
+ # You can add other custom setup tasks here if needed.
42
+
43
+ echo "[custom-setup] Custom setup script finished."
44
+
Dockerfile CHANGED
@@ -1,70 +1,29 @@
1
- FROM ghcr.io/coder/coder:latest
2
 
3
  USER root
4
 
5
  RUN apk add curl unzip
6
 
7
- # Create directory for the Terraform CLI (and assets)
8
- RUN mkdir -p /opt/terraform
9
-
10
- # Terraform is already included in the official Coder image.
11
- # See https://github.com/coder/coder/blob/main/scripts/Dockerfile.base#L15
12
- # If you need to install a different version of Terraform, you can do so here.
13
- # The below step is optional if you wish to keep the existing version.
14
- # See https://github.com/coder/coder/blob/main/provisioner/terraform/install.go#L23-L24
15
- # for supported Terraform versions.
16
- ARG TERRAFORM_VERSION=1.11.0
17
- RUN apk update && \
18
- curl -LOs https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
19
- && unzip -o terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
20
- && mv terraform /opt/terraform \
21
- && rm terraform_${TERRAFORM_VERSION}_linux_amd64.zip
22
- ENV PATH=/opt/terraform:${PATH}
23
-
24
- # Additionally, a Terraform mirror needs to be configured
25
- # to download the Terraform providers used in Coder templates.
26
- # There are two options:
27
-
28
- # Option 1) Use a filesystem mirror.
29
- # We can seed this at build-time or by mounting a volume to
30
- # /opt/terraform/plugins in the container.
31
- # https://developer.hashicorp.com/terraform/cli/config/config-file#filesystem_mirror
32
- # Be sure to add all the providers you use in your templates to /opt/terraform/plugins
33
-
34
- RUN mkdir -p /home/coder/.terraform.d/plugins/registry.terraform.io
35
- ADD filesystem-mirror-example.tfrc /home/coder/.terraformrc
36
-
37
- # Optionally, we can "seed" the filesystem mirror with common providers.
38
- # Comment out lines 40-49 if you plan on only using a volume or network mirror:
39
- WORKDIR /home/coder/.terraform.d/plugins/registry.terraform.io
40
- ARG CODER_PROVIDER_VERSION=2.2.0
41
- RUN echo "Adding coder/coder v${CODER_PROVIDER_VERSION}" \
42
- && mkdir -p coder/coder && cd coder/coder \
43
- && curl -LOs https://github.com/coder/terraform-provider-coder/releases/download/v${CODER_PROVIDER_VERSION}/terraform-provider-coder_${CODER_PROVIDER_VERSION}_linux_amd64.zip
44
- ARG DOCKER_PROVIDER_VERSION=3.0.2
45
- RUN echo "Adding kreuzwerker/docker v${DOCKER_PROVIDER_VERSION}" \
46
- && mkdir -p kreuzwerker/docker && cd kreuzwerker/docker \
47
- && curl -LOs https://github.com/kreuzwerker/terraform-provider-docker/releases/download/v${DOCKER_PROVIDER_VERSION}/terraform-provider-docker_${DOCKER_PROVIDER_VERSION}_linux_amd64.zip
48
- ARG KUBERNETES_PROVIDER_VERSION=2.36.0
49
- RUN echo "Adding kubernetes/kubernetes v${KUBERNETES_PROVIDER_VERSION}" \
50
- && mkdir -p hashicorp/kubernetes && cd hashicorp/kubernetes \
51
- && curl -LOs https://releases.hashicorp.com/terraform-provider-kubernetes/${KUBERNETES_PROVIDER_VERSION}/terraform-provider-kubernetes_${KUBERNETES_PROVIDER_VERSION}_linux_amd64.zip
52
- ARG AWS_PROVIDER_VERSION=5.89.0
53
- RUN echo "Adding aws/aws v${AWS_PROVIDER_VERSION}" \
54
- && mkdir -p aws/aws && cd aws/aws \
55
- && curl -LOs https://releases.hashicorp.com/terraform-provider-aws/${AWS_PROVIDER_VERSION}/terraform-provider-aws_${AWS_PROVIDER_VERSION}_linux_amd64.zip
56
-
57
- RUN chown -R coder:coder /home/coder/.terraform*
58
- WORKDIR /home/coder
59
-
60
- # Option 2) Use a network mirror.
61
- # https://developer.hashicorp.com/terraform/cli/config/config-file#network_mirror
62
- # Be sure uncomment line 60 and edit network-mirror-example.tfrc to
63
- # specify the HTTPS base URL of your mirror.
64
-
65
- # ADD network-mirror-example.tfrc /home/coder/.terraformrc
66
-
67
- USER coder
68
-
69
- # Use the .terraformrc file to inform Terraform of the locally installed providers.
70
- ENV TF_CLI_CONFIG_FILE=/home/coder/.terraformrc
 
1
+ FROM codercom/code-server:latest
2
 
3
  USER root
4
 
5
  RUN apk add curl unzip
6
 
7
+ # Environment variables that will be used by entrypoint or code-server
8
+ # PASSWORD will be injected by Hugging Face Secrets
9
+ # PORT is often set by Hugging Face Spaces (defaulting to 7860 if not set)
10
+ ENV PORT=${PORT:-7860}
11
+ ENV DEFAULT_WORKSPACE=/home/coder/project
12
+ ENV USER_DATA_DIR=/home/coder/.local/share/code-server
13
+ ENV EXTENSIONS_DIR=${USER_DATA_DIR}/extensions
14
+ ENV CONFIG_DIR=/home/coder/.config/code-server
15
+
16
+ # Copy the entrypoint script to a location accessible by the 'coder' user
17
+ # The base image runs as 'coder' user.
18
+ COPY --chown=coder:coder entrypoint.sh /home/coder/entrypoint.sh
19
+ RUN chmod +x /home/coder/entrypoint.sh
20
+
21
+ # Expose the port code-server will listen on
22
+ EXPOSE ${PORT}
23
+
24
+ # Set the entrypoint. The script will handle starting code-server.
25
+ ENTRYPOINT ["/home/coder/entrypoint.sh"]
26
+
27
+ # Default argument to the entrypoint, which can be the workspace to open.
28
+ # The entrypoint script currently hardcodes this, but this is a common pattern.
29
+ CMD ["/home/coder/project"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Dockerfile.bak ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM codercom/code-server:latest
2
+
3
+ # Environment variables that will be used by entrypoint or code-server
4
+ # PASSWORD will be injected by Hugging Face Secrets
5
+ # PORT is often set by Hugging Face Spaces (defaulting to 7860 if not set)
6
+ ENV PORT=${PORT:-7860}
7
+ ENV DEFAULT_WORKSPACE=/home/coder/project
8
+ ENV USER_DATA_DIR=/home/coder/.local/share/code-server
9
+ ENV EXTENSIONS_DIR=${USER_DATA_DIR}/extensions
10
+ ENV CONFIG_DIR=/home/coder/.config/code-server
11
+
12
+ # Copy the entrypoint script to a location accessible by the 'coder' user
13
+ # The base image runs as 'coder' user.
14
+ COPY --chown=coder:coder entrypoint.sh /home/coder/entrypoint.sh
15
+ RUN chmod +x /home/coder/entrypoint.sh
16
+
17
+ # Expose the port code-server will listen on
18
+ EXPOSE ${PORT}
19
+
20
+ # Set the entrypoint. The script will handle starting code-server.
21
+ ENTRYPOINT ["/home/coder/entrypoint.sh"]
22
+
23
+ # Default argument to the entrypoint, which can be the workspace to open.
24
+ # The entrypoint script currently hardcodes this, but this is a common pattern.
25
+ CMD ["/home/coder/project"]
entrypoint.sh ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Default port, can be overridden by PORT env var from Hugging Face
5
+ APP_PORT=${PORT:-7860}
6
+
7
+ # Default workspace, can be overridden by args to this script or Docker CMD
8
+ DEFAULT_WORKSPACE_PATH=${1:-/home/coder/project}
9
+
10
+ # Ensure necessary directories exist and have correct permissions for the 'coder' user
11
+ # These are usually created by the base image, but good to ensure.
12
+ mkdir -p "${DEFAULT_WORKSPACE_PATH}"
13
+ mkdir -p "${USER_DATA_DIR}" # Typically /home/coder/.local/share/code-server
14
+ mkdir -p "${EXTENSIONS_DIR}" # Typically /home/coder/.local/share/code-server/extensions
15
+ mkdir -p "${CONFIG_DIR}" # Typically /home/coder/.config/code-server
16
+
17
+ # Change ownership to coder user if script is run as root initially (not expected in HF Spaces)
18
+ # However, Hugging Face Spaces usually run as a non-root user that matches the Dockerfile USER.
19
+ # The codercom/code-server image already runs as 'coder' (UID 1000, GID 1000).
20
+ # So, explicit chown might not be strictly necessary here if files are copied with --chown=coder:coder
21
+ # and directories are created by the 'coder' user process.
22
+
23
+ echo "Ensuring correct ownership for coder user..."
24
+ # Since we are running as coder user (defined in base image), these should already be owned by coder.
25
+ # If not, it means something is wrong with the base image or execution context.
26
+ # We'll skip chown for now as it might fail in restricted environments if not run as root.
27
+
28
+ # Install extensions if they are not already installed
29
+ # List of extensions to install
30
+ EXTENSIONS_TO_INSTALL=(
31
+ "ms-python.python"
32
+ "dbaeumer.vscode-eslint"
33
+ "ms-ceintl.vscode-language-pack-zh-hans"
34
+ "rooveterinaryinc.roo-cline"
35
+ )
36
+
37
+ INSTALLED_EXTENSIONS_LIST=$(code-server --list-extensions --extensions-dir "${EXTENSIONS_DIR}")
38
+
39
+ for EXTENSION_ID in "${EXTENSIONS_TO_INSTALL[@]}"; do
40
+ if echo "${INSTALLED_EXTENSIONS_LIST}" | grep -qi "${EXTENSION_ID}"; then
41
+ echo "Extension ${EXTENSION_ID} is already installed."
42
+ else
43
+ echo "Installing extension ${EXTENSION_ID}..."
44
+ code-server --extensions-dir "${EXTENSIONS_DIR}" --install-extension "${EXTENSION_ID}" || echo "Failed to install extension ${EXTENSION_ID}, continuing..."
45
+ fi
46
+ done
47
+
48
+ # Prepare arguments for code-server
49
+ ARGS=(
50
+ "--bind-addr" "0.0.0.0:${APP_PORT}"
51
+ "--user-data-dir" "${USER_DATA_DIR}"
52
+ "--extensions-dir" "${EXTENSIONS_DIR}"
53
+ "--config" "${CONFIG_DIR}/config.yaml"
54
+ "--auth" "password" # Use password authentication
55
+ # "--disable-telemetry" # Optional: disable telemetry
56
+ )
57
+
58
+ # If PASSWORD environment variable is set (from Hugging Face Secrets), use it.
59
+ # The base image itself will pick up the PASSWORD env var if --auth password is set.
60
+ if [ -n "${PASSWORD}" ]; then
61
+ echo "Password environment variable is set. code-server will use it."
62
+ else
63
+ echo "WARNING: PASSWORD environment variable is not set. code-server might start without a password or with a default one if not configured otherwise."
64
+ fi
65
+
66
+ # The last argument is the workspace directory to open
67
+ ARGS+=("${DEFAULT_WORKSPACE_PATH}")
68
+
69
+ echo "Starting code-server on port ${APP_PORT} with workspace ${DEFAULT_WORKSPACE_PATH}..."
70
+
71
+ # Execute code-server with all arguments
72
+ # The PASSWORD env var is automatically picked up by code-server when --auth password is used.
73
+ exec code-server "${ARGS[@]}"
74
+