Skip to content

Commit 0abc398

Browse files
committed
feat(docker): enhance GitHub Actions runner configuration
- Adds new Docker command options for GitHub Actions runners to improve flexibility and usability. - Introduces an entrypoint script for setup, cleanup, and configuration of runners. - Archives old installation scripts in favor of official GitHub Actions setup actions for better management and version handling. Improves environment variable documentation for better clarity on required configurations.
1 parent a4dab73 commit 0abc398

File tree

9 files changed

+201
-21
lines changed

9 files changed

+201
-21
lines changed

.claude/settings.local.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
"Bash(mv:*)",
1313
"WebFetch(domain:learn.microsoft.com)",
1414
"Bash(find:*)",
15-
"Bash(chmod:*)"
15+
"Bash(chmod:*)",
16+
"Bash(docker logs:*)",
17+
"Bash(docker exec:*)",
18+
"Bash(docker stop:*)",
19+
"Bash(docker rm:*)"
1620
],
1721
"deny": []
1822
}

README.md

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,59 @@ docker pull ghcr.io/emberstack/github-actions-runner:latest
2929
```
3030

3131
### Run as GitHub Actions Runner
32+
33+
#### Using Personal Access Token (PAT)
3234
```bash
3335
docker run -d \
3436
--name github-runner \
35-
-e RUNNER_NAME="my-runner" \
36-
-e GITHUB_TOKEN="your-github-token" \
37-
-e RUNNER_REPOSITORY_URL="https://github.com/your-org/your-repo" \
37+
-e GITHUB_RUNNER_URL="https://github.com/your-org/your-repo" \
38+
-e GITHUB_RUNNER_PAT="your-personal-access-token" \
39+
-e GITHUB_RUNNER_NAME="my-runner" \
40+
-e GITHUB_RUNNER_LABELS="docker,linux" \
3841
emberstack/github-actions-runner:latest
3942
```
4043

44+
#### Using Registration Token
45+
```bash
46+
docker run -d \
47+
--name github-runner \
48+
-e GITHUB_RUNNER_URL="https://github.com/your-org/your-repo" \
49+
-e GITHUB_RUNNER_TOKEN="your-registration-token" \
50+
-e GITHUB_RUNNER_NAME="my-runner" \
51+
emberstack/github-actions-runner:latest
52+
```
53+
54+
#### With Docker Socket Access
55+
```bash
56+
docker run -d \
57+
--name github-runner \
58+
-v /var/run/docker.sock:/var/run/docker.sock \
59+
-e GITHUB_RUNNER_URL="https://github.com/your-org/your-repo" \
60+
-e GITHUB_RUNNER_PAT="your-personal-access-token" \
61+
-e GITHUB_RUNNER_DOCKER_SOCK="true" \
62+
emberstack/github-actions-runner:latest
63+
```
64+
65+
#### With Custom GID
66+
```bash
67+
docker run -d \
68+
--name github-runner \
69+
-e GITHUB_RUNNER_URL="https://github.com/your-org/your-repo" \
70+
-e GITHUB_RUNNER_PAT="your-personal-access-token" \
71+
-e GITHUB_RUNNER_GID="1001" \
72+
emberstack/github-actions-runner:latest
73+
```
74+
75+
#### Environment Variables
76+
- `GITHUB_RUNNER_URL` (required): Repository, organization, or enterprise URL
77+
- `GITHUB_RUNNER_PAT` or `GITHUB_RUNNER_TOKEN` (required): Authentication token
78+
- `GITHUB_RUNNER_NAME` (optional): Runner name (defaults to hostname)
79+
- `GITHUB_RUNNER_LABELS` (optional): Comma-separated list of labels
80+
- `GITHUB_RUNNER_GROUP` (optional): Runner group name
81+
- `GITHUB_RUNNER_WORKDIR` (optional): Working directory for jobs
82+
- `GITHUB_RUNNER_GID` (optional): Custom GID to create github-actions-runner group
83+
- `GITHUB_RUNNER_DOCKER_SOCK` (optional): Set to "true" to auto-configure Docker socket access
84+
4185
## Included Software
4286

4387
### Pre-installed in Base Image
@@ -61,13 +105,11 @@ The following tools are already available in the GitHub Actions runner base imag
61105
- **time** - Time command execution
62106

63107
### Programming Languages & Runtimes
64-
- **Python 3** with pip - Python interpreter and package manager
65108
- **PowerShell Core** - Cross-platform PowerShell
66109

67110
### Cloud & Infrastructure Tools
68111
- **Azure CLI** - Azure cloud management
69112
- **AzCopy** - Azure Storage data transfer (latest release)
70-
- **Ansible** - Infrastructure automation (latest from pip)
71113

72114
### Container Tools
73115
- **Docker Compose Plugin** - Multi-container orchestration (latest)
@@ -230,14 +272,19 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
230272
- Inspired by the need for comprehensive CI/CD environments
231273
- Thanks to all contributors and the open-source community
232274

233-
## Note on .NET SDK, Node.js, and Kubernetes Tools
275+
## Note on Development Tools
234276

235-
While installation scripts for these tools are available in the `src/_archive/scripts/` directory, we recommend using GitHub Actions' official setup actions or marketplace actions in your workflows:
277+
While installation scripts for various development tools are available in the `src/_archive/scripts/` directory, we recommend using GitHub Actions' official setup actions or marketplace actions in your workflows:
236278

279+
### Languages & Runtimes
280+
- **Python/pip**: Use [`actions/setup-python`](https://github.com/actions/setup-python) - includes pip by default
237281
- **Node.js**: Use [`actions/setup-node`](https://github.com/actions/setup-node)
238282
- **.NET SDK**: Use [`actions/setup-dotnet`](https://github.com/actions/setup-dotnet)
283+
284+
### Infrastructure Tools
239285
- **kubectl**: Use [`azure/setup-kubectl`](https://github.com/azure/setup-kubectl)
240286
- **Helm**: Use [`azure/setup-helm`](https://github.com/azure/setup-helm)
241287
- **Kustomize**: Use [`imranismail/setup-kustomize`](https://github.com/imranismail/setup-kustomize)
288+
- **Ansible**: Install via pip after setting up Python
242289

243290
These actions provide better caching, version management, and are optimized for CI/CD environments.

src/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,15 @@ COPY setup.sh /
2525
# Run setup script with proper error handling
2626
RUN bash -e /setup.sh
2727

28-
USER runner
28+
# Copy entrypoint script
29+
COPY entrypoint.sh /entrypoint.sh
30+
RUN chmod +x /entrypoint.sh
31+
32+
# Switch back to runner user
33+
USER runner
34+
35+
# Set working directory
36+
WORKDIR /home/runner
37+
38+
# Set entrypoint
39+
ENTRYPOINT ["/entrypoint.sh"]

src/_archive/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ This directory contains installation scripts that have been archived in favor of
44

55
## Archived Scripts
66

7+
### Python/pip Installation (`scripts/install-python.sh`)
8+
- **Replaced by**: [`actions/setup-python`](https://github.com/actions/setup-python)
9+
- **Reason**: The official action includes pip by default and provides Python version management
10+
711
### Node.js Installation (`scripts/install-nodejs.sh`)
812
- **Replaced by**: [`actions/setup-node`](https://github.com/actions/setup-node)
913
- **Reason**: The official action provides better caching, version management, and is optimized for CI/CD
@@ -19,6 +23,10 @@ This directory contains installation scripts that have been archived in favor of
1923
- Kustomize: [`imranismail/setup-kustomize`](https://github.com/imranismail/setup-kustomize)
2024
- **Reason**: These actions provide version management, caching, and are maintained by the community
2125

26+
### Ansible Installation (`scripts/install-ansible.sh`)
27+
- **Replaced by**: pip install after `actions/setup-python`
28+
- **Reason**: Ansible is a Python package best installed via pip in workflows
29+
2230
## Usage
2331

2432
These scripts are preserved for reference and can still be used if you need to install these tools directly in the Docker image. However, for GitHub Actions workflows, we recommend using the official setup actions.
@@ -51,4 +59,15 @@ steps:
5159
uses: azure/setup-helm@v4
5260
with:
5361
version: 'latest'
62+
63+
- name: Setup Python
64+
uses: actions/setup-python@v5
65+
with:
66+
python-version: '3.x'
67+
cache: 'pip'
68+
69+
- name: Install Ansible
70+
run: |
71+
python -m pip install --upgrade pip
72+
pip install ansible
5473
```
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/entrypoint.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Switch to runner user home directory
5+
cd /home/runner
6+
7+
# Function to handle runner cleanup
8+
cleanup_runner() {
9+
echo "Attempting to remove existing runner configuration..."
10+
if [ -n "${GITHUB_RUNNER_PAT}" ]; then
11+
./config.sh remove --pat "${GITHUB_RUNNER_PAT}" || true
12+
elif [ -n "${GITHUB_RUNNER_TOKEN}" ]; then
13+
./config.sh remove --token "${GITHUB_RUNNER_TOKEN}" || true
14+
else
15+
echo "No PAT or TOKEN provided for runner removal, skipping cleanup"
16+
fi
17+
}
18+
19+
# Function to configure runner
20+
configure_runner() {
21+
echo "Configuring GitHub Actions runner..."
22+
23+
# Build configuration command
24+
CONFIG_CMD="./config.sh --url \"${GITHUB_RUNNER_URL}\" --unattended --replace"
25+
26+
# Add authentication (prefer PAT over TOKEN)
27+
if [ -n "${GITHUB_RUNNER_PAT}" ]; then
28+
CONFIG_CMD="${CONFIG_CMD} --pat \"${GITHUB_RUNNER_PAT}\""
29+
elif [ -n "${GITHUB_RUNNER_TOKEN}" ]; then
30+
CONFIG_CMD="${CONFIG_CMD} --token \"${GITHUB_RUNNER_TOKEN}\""
31+
else
32+
echo "ERROR: Either GITHUB_RUNNER_PAT or GITHUB_RUNNER_TOKEN must be provided"
33+
exit 1
34+
fi
35+
36+
# Add runner name (use hostname as default)
37+
if [ -n "${GITHUB_RUNNER_NAME}" ]; then
38+
CONFIG_CMD="${CONFIG_CMD} --name \"${GITHUB_RUNNER_NAME}\""
39+
else
40+
CONFIG_CMD="${CONFIG_CMD} --name \"$(hostname)\""
41+
fi
42+
43+
# Add labels if provided
44+
if [ -n "${GITHUB_RUNNER_LABELS}" ]; then
45+
CONFIG_CMD="${CONFIG_CMD} --labels \"${GITHUB_RUNNER_LABELS}\""
46+
fi
47+
48+
# Add runner group if provided
49+
if [ -n "${GITHUB_RUNNER_GROUP}" ]; then
50+
CONFIG_CMD="${CONFIG_CMD} --runnergroup \"${GITHUB_RUNNER_GROUP}\""
51+
fi
52+
53+
# Add work directory if provided
54+
if [ -n "${GITHUB_RUNNER_WORKDIR}" ]; then
55+
CONFIG_CMD="${CONFIG_CMD} --work \"${GITHUB_RUNNER_WORKDIR}\""
56+
fi
57+
58+
# Execute configuration
59+
eval ${CONFIG_CMD}
60+
}
61+
62+
# Function to setup groups
63+
setup_groups() {
64+
# Handle custom GID if specified
65+
if [ -n "${GITHUB_RUNNER_GID}" ]; then
66+
echo "Creating github-actions-runner group with GID ${GITHUB_RUNNER_GID}..."
67+
sudo groupadd -f -g ${GITHUB_RUNNER_GID} github-actions-runner || true
68+
sudo usermod -aG github-actions-runner runner
69+
echo "Added runner user to github-actions-runner group"
70+
fi
71+
72+
# Handle Docker socket access if requested
73+
if [ "${GITHUB_RUNNER_DOCKER_SOCK}" = "true" ]; then
74+
if [ -S /var/run/docker.sock ]; then
75+
DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)
76+
echo "Docker socket detected with GID ${DOCKER_GID}"
77+
echo "Creating github-actions-runner-dockersock group..."
78+
sudo groupadd -f -g ${DOCKER_GID} github-actions-runner-dockersock || true
79+
sudo usermod -aG github-actions-runner-dockersock runner
80+
echo "Added runner user to github-actions-runner-dockersock group"
81+
else
82+
echo "WARNING: GITHUB_RUNNER_DOCKER_SOCK=true but /var/run/docker.sock not found"
83+
fi
84+
fi
85+
}
86+
87+
# Main execution
88+
main() {
89+
# Validate required environment variables
90+
if [ -z "${GITHUB_RUNNER_URL}" ]; then
91+
echo "ERROR: GITHUB_RUNNER_URL environment variable is required"
92+
echo "Example: https://github.com/myorg/myrepo"
93+
exit 1
94+
fi
95+
96+
# Setup groups if needed
97+
setup_groups
98+
99+
# Cleanup any existing runner configuration
100+
cleanup_runner
101+
102+
# Configure the runner
103+
configure_runner
104+
105+
# Start the runner
106+
echo "Starting GitHub Actions runner..."
107+
exec ./run.sh
108+
}
109+
110+
# Execute main function
111+
main

src/setup.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ setup:
1111
script: "scripts/install-archive-tools.sh"
1212
description: "Installs compression and archive tools (p7zip, zip)"
1313

14-
- name: "Install Python and pip"
15-
script: "scripts/install-python.sh"
16-
description: "Installs pip and Python dev tools (Python3 is pre-installed)"
17-
1814
- name: "Install PowerShell"
1915
script: "scripts/install-powershell.sh"
2016
description: "Installs PowerShell Core"
@@ -27,18 +23,10 @@ setup:
2723
script: "scripts/install-azcopy.sh"
2824
description: "Installs AzCopy for Azure Storage"
2925

30-
- name: "Install Ansible"
31-
script: "scripts/install-ansible.sh"
32-
description: "Installs Ansible using pip"
33-
3426
- name: "Install Docker tools"
3527
script: "scripts/install-docker-tools.sh"
3628
description: "Installs Docker Compose plugin"
3729

38-
- name: "Install yamllint"
39-
script: "scripts/install-yamllint.sh"
40-
description: "Installs yamllint for YAML validation"
41-
4230
- name: "Install GitHub CLI"
4331
script: "scripts/install-github-cli.sh"
4432
description: "Installs GitHub CLI (gh)"

0 commit comments

Comments
 (0)