Skip to content

Commit 46dc07d

Browse files
authored
Merge pull request #1 from irfansofyana/publish-docker
Publish docker
2 parents 7b88b31 + 3a17097 commit 46dc07d

File tree

10 files changed

+649
-8
lines changed

10 files changed

+649
-8
lines changed

.dockerignore

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Build artifacts
2+
bin/
3+
*.exe
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool
12+
*.out
13+
14+
# Logs
15+
logs
16+
lwmcp
17+
*.log
18+
19+
# Environment files
20+
.env
21+
.env.*
22+
23+
# Git
24+
.git/
25+
.gitignore
26+
.github/
27+
28+
# Documentation (not needed in container)
29+
*.md
30+
!api/*.md
31+
docs/
32+
33+
# IDE and editor files
34+
.vscode/
35+
.idea/
36+
*.swp
37+
*.swo
38+
*~
39+
40+
# macOS
41+
.DS_Store
42+
43+
# License (not needed in runtime)
44+
LICENSE
45+
46+
# CI/CD
47+
.github/
48+
49+
# Development and testing
50+
examples/
51+
test/
52+
tests/
53+
54+
# Go workspace
55+
go.work
56+
go.work.sum
57+
58+
# Temporary files
59+
tmp/
60+
temp/
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*.*.*'
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Log in to GitHub Container Registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Extract metadata (tags, labels) for Docker
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
tags: |
41+
# Tag with 'latest' on main branch
42+
type=raw,value=latest,enable={{is_default_branch}}
43+
# Tag with version on tags (e.g., v1.0.0 -> 1.0.0)
44+
type=semver,pattern={{version}}
45+
# Tag with major.minor on tags (e.g., v1.0.0 -> 1.0)
46+
type=semver,pattern={{major}}.{{minor}}
47+
# Tag with major on tags (e.g., v1.0.0 -> 1)
48+
type=semver,pattern={{major}}
49+
# Tag with full version including 'v' prefix (e.g., v1.0.0)
50+
type=semver,pattern=v{{version}}
51+
# Tag with SHA for commits
52+
type=sha,prefix={{branch}}-
53+
54+
- name: Build and push Docker image
55+
uses: docker/build-push-action@v5
56+
with:
57+
context: .
58+
platforms: linux/amd64,linux/arm64
59+
push: true
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
build-args: |
63+
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
64+
COMMIT=${{ github.sha }}
65+
BUILD_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
66+
cache-from: type=gha
67+
cache-to: type=gha,mode=max
68+
69+
- name: Output image details
70+
run: |
71+
echo "### Docker Image Published! :rocket:" >> $GITHUB_STEP_SUMMARY
72+
echo "" >> $GITHUB_STEP_SUMMARY
73+
echo "**Registry:** ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY
74+
echo "**Image:** ${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY
75+
echo "" >> $GITHUB_STEP_SUMMARY
76+
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
77+
echo '```' >> $GITHUB_STEP_SUMMARY
78+
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
79+
echo '```' >> $GITHUB_STEP_SUMMARY
80+
echo "" >> $GITHUB_STEP_SUMMARY
81+
echo "**Pull command:**" >> $GITHUB_STEP_SUMMARY
82+
echo '```bash' >> $GITHUB_STEP_SUMMARY
83+
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
84+
echo '```' >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ bin/
33

44
# Log files
55
logs
6-
lwmcp
6+
lwmcp
7+
*.log
8+
9+
# Environment files
10+
.env
11+
.env.*
12+
13+
# macOS
14+
.DS_Store

0 commit comments

Comments
 (0)