Skip to content

Commit 5d61709

Browse files
committed
chore: add GitHub Actions workflow for Docker build and publish
1 parent 3459e79 commit 5d61709

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

.github/workflows/docker.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: docker
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
env:
10+
REGISTRY: docker.io
11+
IMAGE_NAME: dev-to-mcp
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Build image for validation
24+
uses: docker/build-push-action@v5
25+
with:
26+
context: .
27+
file: Dockerfile
28+
push: false
29+
tags: ${{ env.IMAGE_NAME }}:ci-${{ github.sha }}
30+
cache-from: type=gha
31+
cache-to: type=gha,mode=max
32+
33+
publish:
34+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
35+
needs: build
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v4
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@v3
43+
44+
- name: Log in to Docker Hub
45+
uses: docker/login-action@v3
46+
with:
47+
registry: ${{ env.REGISTRY }}
48+
username: ${{ secrets.DOCKERHUB_USERNAME }}
49+
password: ${{ secrets.DOCKERHUB_TOKEN }}
50+
51+
- name: Build and push image
52+
uses: docker/build-push-action@v5
53+
with:
54+
context: .
55+
file: Dockerfile
56+
push: true
57+
tags: |
58+
${{ env.REGISTRY }}/${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
59+
${{ env.REGISTRY }}/${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
60+
cache-from: type=gha
61+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)