Skip to content

Commit db8bd17

Browse files
committed
feat: prevent Docker publishing from template repository
- Add template detection logic to disable publishing from template repo - Enable publishing only for consuming repositories after customization - Add explicit checks for template indicators in README.md - Update documentation to clarify publishing behavior - Protect template repository from accidental Docker image publishing
1 parent d620a43 commit db8bd17

File tree

3 files changed

+60
-20
lines changed

3 files changed

+60
-20
lines changed

.github/workflows/docker-publish.yml

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,52 @@ env:
1919
IMAGE_NAME: ${{ github.repository }}
2020

2121
jobs:
22+
# Check if this is a template repository or a consuming repository
23+
check-repo-type:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
is-template: ${{ steps.check.outputs.is-template }}
27+
should-publish: ${{ steps.check.outputs.should-publish }}
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
33+
- name: Check repository type
34+
id: check
35+
run: |
36+
# Check if this is a template repository by looking for template indicators
37+
# Template repositories typically have specific patterns in their files
38+
if [[ "${{ github.repository }}" == "droq-ai/dfx-base-node-template-py" ]]; then
39+
echo "is-template=true" >> $GITHUB_OUTPUT
40+
echo "should-publish=false" >> $GITHUB_OUTPUT
41+
echo "::notice::This is the template repository - Docker publishing is disabled"
42+
elif grep -q "droq-node-template" README.md 2>/dev/null && \
43+
grep -q "Replace src/node/main.py with your code" README.md 2>/dev/null; then
44+
echo "is-template=true" >> $GITHUB_OUTPUT
45+
echo "should-publish=false" >> $GITHUB_OUTPUT
46+
echo "::notice::Template repository detected - Docker publishing is disabled. Consumers should customize before publishing."
47+
else
48+
echo "is-template=false" >> $GITHUB_OUTPUT
49+
50+
# Determine if should publish based on event
51+
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]] || \
52+
[[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/* ]] || \
53+
[[ "${{ github.event.inputs.publish }}" == "true" ]]; then
54+
echo "should-publish=true" >> $GITHUB_OUTPUT
55+
echo "::notice::Consuming repository detected - Docker publishing is enabled"
56+
else
57+
echo "should-publish=false" >> $GITHUB_OUTPUT
58+
fi
59+
fi
60+
2261
build-and-test:
2362
runs-on: ubuntu-latest
63+
needs: check-repo-type
2464
outputs:
2565
image-digest: ${{ steps.build.outputs.digest }}
2666
image-tag: ${{ steps.meta.outputs.tags }}
27-
should-publish: ${{ steps.should-publish.outputs.result }}
67+
should-publish: ${{ needs.check-repo-type.outputs.should-publish }}
2868

2969
steps:
3070
- name: Checkout repository
@@ -46,17 +86,6 @@ jobs:
4686
type=semver,pattern={{major}}
4787
type=raw,value=latest,enable={{is_default_branch}}
4888
49-
- name: Determine if should publish
50-
id: should-publish
51-
run: |
52-
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]] || \
53-
[[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/* ]] || \
54-
[[ "${{ github.event.inputs.publish }}" == "true" ]]; then
55-
echo "result=true" >> $GITHUB_OUTPUT
56-
else
57-
echo "result=false" >> $GITHUB_OUTPUT
58-
fi
59-
6089
- name: Build Docker image
6190
id: build
6291
uses: docker/build-push-action@v5
@@ -73,7 +102,7 @@ jobs:
73102

74103
publish:
75104
runs-on: ubuntu-latest
76-
needs: build-and-test
105+
needs: [check-repo-type, build-and-test]
77106
if: needs.build-and-test.outputs.should-publish == 'true'
78107
environment: production
79108

@@ -131,7 +160,7 @@ jobs:
131160

132161
publish-private-registry:
133162
runs-on: ubuntu-latest
134-
needs: build-and-test
163+
needs: [check-repo-type, build-and-test]
135164
if: needs.build-and-test.outputs.should-publish == 'true' && secrets.PRIVATE_REGISTRY_URL != ''
136165
environment: production
137166

@@ -174,7 +203,7 @@ jobs:
174203

175204
security-scan:
176205
runs-on: ubuntu-latest
177-
needs: [build-and-test, publish]
206+
needs: [check-repo-type, build-and-test, publish]
178207
if: needs.build-and-test.outputs.should-publish == 'true'
179208
environment: production
180209

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ uv add package-name
6868

6969
## Docker Publishing
7070

71-
The template includes GitHub Actions for automatic Docker publishing:
71+
The template includes GitHub Actions for automatic Docker publishing that is **disabled for the template repository** and **enabled for consuming repositories**.
7272

73+
**Template Repository**: Docker publishing is automatically disabled
74+
**Consuming Repositories**: Publishing is enabled after customization
75+
76+
**Features:**
7377
- **Triggers**: Push to main, git tags, manual dispatch
7478
- **Registries**: GitHub Container Registry (default) + private registries
7579
- **Platforms**: linux/amd64, linux/arm64
76-
- **Features**: Security scanning, SBOM generation
80+
- **Security**: Security scanning, SBOM generation
7781

78-
Configure private registry with secrets:
82+
**Private Registry Setup:**
7983
- `PRIVATE_REGISTRY_URL`
8084
- `PRIVATE_REGISTRY_USERNAME`
8185
- `PRIVATE_REGISTRY_PASSWORD`

docs/docker-publishing.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# Docker Publishing
22

3-
Automated Docker publishing via GitHub Actions.
3+
Automated Docker publishing via GitHub Actions with template detection.
44

5-
## Setup
5+
## Template Protection
6+
7+
**Template Repository**: Docker publishing is **disabled** to prevent accidental publishing
8+
**Consuming Repositories**: Docker publishing is **enabled** automatically after customization
9+
10+
The workflow detects template repositories and prevents publishing from the template itself.
11+
12+
## Setup for Consuming Repositories
613

714
**Triggers:**
815
- Push to main branch → `latest` tag

0 commit comments

Comments
 (0)