initial commit
This commit is contained in:
20
Dockerfile
Normal file
20
Dockerfile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
FROM golang:alpine
|
||||||
|
|
||||||
|
# Install required tools
|
||||||
|
RUN apk add --no-cache git ca-certificates bash
|
||||||
|
|
||||||
|
# Set working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy entrypoint script
|
||||||
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
||||||
|
# Default environment values (can be overridden at runtime)
|
||||||
|
ENV GIT_REPO=""
|
||||||
|
ENV APP_PATH="."
|
||||||
|
ENV GIT_USERNAME=""
|
||||||
|
ENV GIT_TOKEN=""
|
||||||
|
ENV PACKAGES=""
|
||||||
|
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
39
README.md
Normal file
39
README.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# 🐳 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`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ 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
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🧪 Example Usage
|
||||||
|
|
||||||
|
```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
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 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 |
|
||||||
|
|
||||||
|
## 📄 License
|
||||||
|
|
||||||
|
MIT License – feel free to modify and use.
|
50
entrypoint.sh
Normal file
50
entrypoint.sh
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
error() {
|
||||||
|
echo "[ERROR] $1" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -z "$GIT_REPO" ]; then
|
||||||
|
error "GIT_REPO is not set."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install runtime packages if specified
|
||||||
|
if [ -n "$PACKAGES" ]; then
|
||||||
|
echo "[PKG] Installing additional APK packages: $PACKAGES"
|
||||||
|
apk update >/dev/null
|
||||||
|
apk add --no-cache $(echo "$PACKAGES" | tr ',' ' ')
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract Git host
|
||||||
|
GIT_HOST=$(echo "$GIT_REPO" | awk -F/ '{print $3}')
|
||||||
|
|
||||||
|
# Configure .netrc
|
||||||
|
if [ -n "$GIT_USERNAME" ] && [ -n "$GIT_TOKEN" ]; then
|
||||||
|
echo "[AUTH] Configuring .netrc for Git authentication..."
|
||||||
|
cat <<EOF > ~/.netrc
|
||||||
|
machine $GIT_HOST
|
||||||
|
login $GIT_USERNAME
|
||||||
|
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
|
||||||
|
|
||||||
|
# Clean previous checkout
|
||||||
|
rm -rf /app/repo
|
||||||
|
|
||||||
|
echo "[CLONE] Cloning repository: $GIT_REPO"
|
||||||
|
git clone "$GIT_REPO" repo
|
||||||
|
|
||||||
|
cd repo/"${APP_PATH:-.}"
|
||||||
|
|
||||||
|
echo "[BUILD] Building..."
|
||||||
|
go build -o /app/app .
|
||||||
|
|
||||||
|
echo "[RUN] Starting application..."
|
||||||
|
exec /app/app
|
Reference in New Issue
Block a user