Compare commits

7 Commits
v0.0.1 ... main

Author SHA1 Message Date
62ce179470 improved build.sh 2025-06-06 17:45:20 +02:00
9213dc0c2f added GIT_REF 2025-06-06 17:33:37 +02:00
cfccc65f85 added build script 2025-06-06 15:40:48 +02:00
fce0f66315 changed readme 2025-06-06 15:39:56 +02:00
7f5212d6d4 added support for arm v7 2025-06-06 15:39:31 +02:00
e3bd0b1358 improved readme and added license 2025-06-06 15:31:02 +02:00
b504cdd820 provide link to repo 2025-06-06 14:13:43 +02:00
4 changed files with 124 additions and 20 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Tordarus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,39 +1,89 @@
# 🐳 Go Builder & Runner Docker Image
This Docker image is designed to **download**, **compile**, and **run** a Go program from a Git repository entirely at **container runtime**. It supports both public and private repositories and works seamlessly across multiple architectures (`amd64`, `arm64`).
This Docker image is designed to **download**, **compile**, and **run** a Go program from a Git repository entirely at **container runtime**. It supports both public and private repositories and works seamlessly across multiple architectures.
🏗️ **Built on Alpine Linux** for a minimal, efficient footprint.
---
## ✅ Features
- ✅ Clones a Go repository at runtime
- ✅ Supports **private Git repositories** using `.netrc`-based auth
- ✅ Builds and runs your Go application
-Multi-architecture: `linux/amd64`, `linux/arm64`
- ✅ Minimal and reproducible container setup
* ✅ Clones a Go repository at runtime
* ✅ Supports **private Git repositories** using `.netrc`-based auth
* ✅ Builds and runs your Go application
*Supports checking out a specific **branch, tag, or commit** via `GIT_REF`
* ✅ Multi-architecture: `linux/amd64`, `linux/arm64`, `linux/arm/v7`
* ✅ Minimal and reproducible container setup with Alpine Linux
---
## 🧪 Example Usage
### 🐚 Docker CLI
```bash
docker run --rm \
-e GIT_REPO=https://github.com/youruser/your-go-app.git \
-e GIT_USERNAME=yourusername \
-e GIT_TOKEN=yourtoken \
gorunner:latest
-e GIT_REPO=https://git.tordarus.net/tordarus/hello-world.git \
-e GIT_REF=main \
tordarus/gorunner:latest
````
### 🐳 Docker Compose
Create a `docker-compose.yml`:
```yaml
version: "3.9"
services:
gorunner:
image: tordarus/gorunner:latest
environment:
GIT_REPO: https://git.tordarus.net/tordarus/hello-world.git
GIT_REF: main # Optional specify branch, tag, or commit
GIT_USERNAME: yourusername # Optional for public repos
GIT_TOKEN: yourtoken # Optional for public repos
APP_PATH: . # Optional subdir of Go app
PACKAGES: curl # Optional comma-separated apk packages
```
Then run it with:
```bash
docker compose up
```
---
## 🔧 Environment Variables
| Variable | Required | Description |
| ---------------------- | -------- | ----------------------------------------------------------------------- |
| `GIT_REPO` | ✅ Yes | The HTTPS Git URL of your Go project |
| `GIT_USERNAME` | Optional | Your Git username (required for private repos) |
| `GIT_TOKEN` | Optional | A personal access token or password (required for private repos) |
| `APP_PATH` | Optional | Relative path to the Go module directory inside the repo (default: `.`) |
| `PACKAGES` | Optional | Comma-separated list of packages to install with `apk` before execution |
| Variable | Required | Description |
| -------------- | -------- | ------------------------------------------------------------------------ |
| `GIT_REPO` | ✅ Yes | The HTTPS Git URL of your Go project |
| `GIT_REF` | Optional | Branch name, tag, or commit hash to checkout after clone (default: HEAD) |
| `GIT_USERNAME` | Optional | Your Git username (required for private repos) |
| `GIT_TOKEN` | Optional | A personal access token or password (required for private repos) |
| `APP_PATH` | Optional | Relative path to the Go module directory inside the repo (default: `.`) |
| `PACKAGES` | Optional | Comma-separated list of packages to install with `apk` before execution |
---
## 📦 Docker Hub
👉 Pull the image from Docker Hub:
**[tordarus/gorunner](https://hub.docker.com/r/tordarus/gorunner)**
---
## 🔗 Source Repository
View the source code:
👉 [https://git.tordarus.net/tordarus/gorunner](https://git.tordarus.net/tordarus/gorunner)
Found a bug or have an idea for improvement?
🛠️ [Create an issue](https://git.tordarus.net/tordarus/gorunner/issues) in the repository.
---
## 📄 License
MIT License feel free to modify and use.
MIT License feel free to modify and use.

25
build.sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh
set -e
# Ensure a version tag is passed as argument
if [ -z "$1" ]; then
echo "Usage: $0 <version-tag>"
exit 1
fi
VERSION="$1"
PLATFORMS="linux/amd64,linux/arm64,linux/arm/v7"
# Build and push versioned tag
echo "🔨 Building tag: $VERSION"
docker buildx build \
--platform "$PLATFORMS" \
-t tordarus/gorunner:"$VERSION" \
--push .
# Build and push latest tag
echo "🔨 Building tag: latest"
docker buildx build \
--platform "$PLATFORMS" \
-t tordarus/gorunner:latest \
--push .

View File

@ -30,7 +30,6 @@ password $GIT_TOKEN
EOF
chmod 600 ~/.netrc
# Prevent Git from prompting and force it to use .netrc
export GIT_ASKPASS=true
export GIT_TERMINAL_PROMPT=0
fi
@ -41,7 +40,16 @@ rm -rf /app/repo
echo "[CLONE] Cloning repository: $GIT_REPO"
git clone "$GIT_REPO" repo
cd repo/"${APP_PATH:-.}"
cd repo
# Checkout specific branch, tag, or commit if provided
if [ -n "$GIT_REF" ]; then
echo "[GIT] Checking out ref: $GIT_REF"
git fetch --all --tags
git checkout "$GIT_REF"
fi
cd "${APP_PATH:-.}"
echo "[BUILD] Building..."
go build -o /app/app .