Skip to content

Commit 6fdd683

Browse files
committed
actions
1 parent 2c06dce commit 6fdd683

File tree

4 files changed

+423
-0
lines changed

4 files changed

+423
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*' # Triggers on version tags like v1.0.0, v2.1.3, etc.
7+
8+
env:
9+
DOCKER_IMAGE_NAME: awkto/kea-gui-reservations # Change to your Docker Hub username/repo
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Extract version from tag
20+
id: extract_version
21+
run: |
22+
# Remove 'v' prefix from tag to get version
23+
VERSION=${GITHUB_REF#refs/tags/v}
24+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
25+
echo "Building version: $VERSION"
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: Log in to Docker Hub
31+
uses: docker/login-action@v3
32+
with:
33+
username: ${{ secrets.DOCKER_USERNAME }}
34+
password: ${{ secrets.DOCKER_PASSWORD }}
35+
36+
- name: Build and push Docker image
37+
uses: docker/build-push-action@v5
38+
with:
39+
context: .
40+
push: true
41+
tags: |
42+
${{ env.DOCKER_IMAGE_NAME }}:${{ steps.extract_version.outputs.VERSION }}
43+
${{ env.DOCKER_IMAGE_NAME }}:latest
44+
platforms: linux/amd64,linux/arm64
45+
cache-from: type=gha
46+
cache-to: type=gha,mode=max
47+
48+
- name: Create GitHub Release
49+
uses: softprops/action-gh-release@v1
50+
with:
51+
generate_release_notes: true
52+
body: |
53+
## Docker Image
54+
55+
Pull the image:
56+
```bash
57+
docker pull ${{ env.DOCKER_IMAGE_NAME }}:${{ steps.extract_version.outputs.VERSION }}
58+
# or
59+
docker pull ${{ env.DOCKER_IMAGE_NAME }}:latest
60+
```
61+
62+
Run the container:
63+
```bash
64+
docker run -p 5000:5000 \
65+
-v $(pwd)/config.yaml:/app/config/config.yaml:ro \
66+
${{ env.DOCKER_IMAGE_NAME }}:${{ steps.extract_version.outputs.VERSION }}
67+
```
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CICD_SETUP.md

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# CI/CD Setup Guide
2+
3+
This project uses GitHub Actions to automatically build and publish Docker images to Docker Hub when you create version tags.
4+
5+
## Prerequisites
6+
7+
1. A Docker Hub account
8+
2. A Docker Hub repository (e.g., `awkto/kea-gui-reservations`)
9+
10+
## Setup Instructions
11+
12+
### Step 1: Configure Docker Hub Repository Name
13+
14+
Edit `.github/workflows/docker-publish.yml` and update the `DOCKER_IMAGE_NAME`:
15+
16+
```yaml
17+
env:
18+
DOCKER_IMAGE_NAME: YOUR_DOCKERHUB_USERNAME/kea-gui-reservations
19+
```
20+
21+
### Step 2: Add Docker Hub Secrets to GitHub
22+
23+
1. Go to your GitHub repository
24+
2. Click **Settings** → **Secrets and variables** → **Actions**
25+
3. Click **New repository secret**
26+
4. Add two secrets:
27+
28+
**Secret 1: DOCKER_USERNAME**
29+
- Name: `DOCKER_USERNAME`
30+
- Value: Your Docker Hub username
31+
32+
**Secret 2: DOCKER_PASSWORD**
33+
- Name: `DOCKER_PASSWORD`
34+
- Value: Your Docker Hub access token (NOT your password!)
35+
36+
#### How to Create a Docker Hub Access Token:
37+
38+
1. Log in to [Docker Hub](https://hub.docker.com/)
39+
2. Click your username → **Account Settings**
40+
3. Go to **Security** → **Access Tokens**
41+
4. Click **New Access Token**
42+
5. Give it a name (e.g., "GitHub Actions")
43+
6. Set permissions to **Read, Write, Delete**
44+
7. Click **Generate**
45+
8. **Copy the token** (you won't be able to see it again!)
46+
9. Use this token as the `DOCKER_PASSWORD` secret value
47+
48+
### Step 3: Create a Version Tag
49+
50+
When you're ready to publish a new version:
51+
52+
```bash
53+
# Commit your changes
54+
git add .
55+
git commit -m "Release version 1.0.0"
56+
57+
# Create and push a version tag
58+
git tag v1.0.0
59+
git push origin v1.0.0
60+
```
61+
62+
Or create a tag for a specific commit:
63+
64+
```bash
65+
git tag v1.0.0 abc1234
66+
git push origin v1.0.0
67+
```
68+
69+
### Step 4: Watch the Build
70+
71+
1. Go to your GitHub repository
72+
2. Click the **Actions** tab
73+
3. You'll see the workflow running
74+
4. Wait for it to complete (usually 2-5 minutes)
75+
76+
### Step 5: Verify the Image
77+
78+
Once the workflow completes:
79+
80+
```bash
81+
# Pull the image
82+
docker pull awkto/kea-gui-reservations:1.0.0
83+
84+
# Or pull the latest
85+
docker pull awkto/kea-gui-reservations:latest
86+
```
87+
88+
## What the Workflow Does
89+
90+
When you push a tag like `v1.0.0`, the workflow:
91+
92+
1. ✅ Checks out your code
93+
2. ✅ Extracts the version number (removes the 'v' prefix)
94+
3. ✅ Builds a Docker image for **multiple platforms** (amd64 and arm64)
95+
4. ✅ Pushes the image with **two tags**:
96+
- `awkto/kea-gui-reservations:1.0.0` (version-specific)
97+
- `awkto/kea-gui-reservations:latest` (always points to newest)
98+
5. ✅ Creates a **GitHub Release** with the tag
99+
6. ✅ Adds release notes with Docker pull/run commands
100+
101+
## Version Tag Format
102+
103+
Use semantic versioning tags:
104+
- `v1.0.0` - Major release
105+
- `v1.1.0` - Minor release (new features)
106+
- `v1.1.1` - Patch release (bug fixes)
107+
- `v2.0.0-beta.1` - Pre-release
108+
109+
The `v` prefix is required!
110+
111+
## Multi-Platform Support
112+
113+
The workflow builds for:
114+
- `linux/amd64` (Intel/AMD x86_64)
115+
- `linux/arm64` (ARM 64-bit, e.g., Raspberry Pi 4, Apple Silicon)
116+
117+
This means the same image works on most systems!
118+
119+
## Caching
120+
121+
The workflow uses GitHub Actions cache to speed up builds:
122+
- First build: ~3-5 minutes
123+
- Subsequent builds: ~1-2 minutes
124+
125+
## Troubleshooting
126+
127+
### Error: "denied: requested access to the resource is denied"
128+
129+
- Check that `DOCKER_USERNAME` and `DOCKER_PASSWORD` secrets are set correctly
130+
- Verify the Docker Hub repository exists
131+
- Make sure the access token has **Write** permissions
132+
133+
### Error: "repository name must be lowercase"
134+
135+
- Update `DOCKER_IMAGE_NAME` to use lowercase only
136+
137+
### Workflow doesn't trigger
138+
139+
- Make sure you pushed the tag: `git push origin v1.0.0`
140+
- Tag must start with `v` followed by a version number
141+
142+
### Want to build on every push?
143+
144+
Change the trigger in `.github/workflows/docker-publish.yml`:
145+
146+
```yaml
147+
on:
148+
push:
149+
branches:
150+
- main
151+
tags:
152+
- 'v*.*.*'
153+
```
154+
155+
## Manual Trigger (Optional)
156+
157+
To allow manual workflow runs, add:
158+
159+
```yaml
160+
on:
161+
push:
162+
tags:
163+
- 'v*.*.*'
164+
workflow_dispatch: # Adds "Run workflow" button in GitHub
165+
```
166+
167+
## Example Release Process
168+
169+
```bash
170+
# 1. Make your changes
171+
git add .
172+
git commit -m "Add new feature"
173+
174+
# 2. Push to main
175+
git push origin main
176+
177+
# 3. When ready to release, create a tag
178+
git tag v1.0.0
179+
git push origin v1.0.0
180+
181+
# 4. Go to GitHub Actions and watch the build
182+
183+
# 5. Once complete, users can pull:
184+
docker pull awkto/kea-gui-reservations:latest
185+
```
186+
187+
## Using the Published Image
188+
189+
Once published, users can use your image:
190+
191+
```bash
192+
# Pull the image
193+
docker pull awkto/kea-gui-reservations:latest
194+
195+
# Run with custom config
196+
docker run -d \
197+
--name kea-gui \
198+
-p 5000:5000 \
199+
-v $(pwd)/config.yaml:/app/config/config.yaml:ro \
200+
awkto/kea-gui-reservations:latest
201+
202+
# Or use docker-compose
203+
docker-compose up -d
204+
```
205+
206+
## Benefits
207+
208+
✅ Automated builds - no manual Docker commands needed
209+
✅ Multi-platform support - works on x86_64 and ARM
210+
✅ Version tracking - every release is tagged
211+
✅ GitHub Releases - automatic changelog
212+
✅ Fast builds - uses layer caching
213+
✅ Latest tag - always points to newest version
214+
215+
---
216+
217+
Need help? Check the [GitHub Actions documentation](https://docs.github.com/en/actions) or open an issue!

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,33 @@ Visit `http://localhost:5000`
117117

118118
## Running with Docker
119119

120+
### Using Pre-built Image (Recommended)
121+
122+
```bash
123+
# Pull the latest image
124+
docker pull awkto/kea-gui-reservations:latest
125+
126+
# Run with your config
127+
docker run -d \
128+
--name kea-gui \
129+
-p 5000:5000 \
130+
-v $(pwd)/config.yaml:/app/config/config.yaml:ro \
131+
awkto/kea-gui-reservations:latest
132+
```
133+
134+
### Building from Source
135+
120136
```bash
121137
docker build -t kea-gui .
122138
docker run -p 5000:5000 -v $(pwd)/config.yaml:/app/config.yaml kea-gui
123139
```
124140

141+
### Using Docker Compose
142+
143+
```bash
144+
docker-compose up -d
145+
```
146+
125147
## API Endpoints
126148

127149
- `GET /api/leases` - Fetch all DHCPv4 leases
@@ -144,6 +166,12 @@ docker run -p 5000:5000 -v $(pwd)/config.yaml:/app/config.yaml kea-gui
144166
- Run container with appropriate user permissions
145167
- Consider network isolation
146168

169+
## CI/CD
170+
171+
This project includes GitHub Actions for automated Docker image builds. See [CICD_SETUP.md](CICD_SETUP.md) for setup instructions.
172+
173+
Docker images are automatically published to Docker Hub on tagged releases.
174+
147175
## License
148176

149177
MIT

0 commit comments

Comments
 (0)