Skip to content

Commit e621d94

Browse files
committed
implement ci-docker.yml file to push the image to GitHub Container Registry GHCR
1 parent e23aab4 commit e621d94

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

.github/workflows/ci-docker.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CI & Docker
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build-test:
11+
runs-on: unbuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Use Node.js 20
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
cache: npm
22+
23+
- name: Install dependencies
24+
run: |
25+
cd server
26+
npm ci
27+
28+
- name: Run tests
29+
run: |
30+
cd server
31+
npm test --if-present
32+
33+
docker-image:
34+
needs: build-test
35+
runs-on: unbuntu-latest
36+
37+
permissions:
38+
contents: read
39+
packages: write
40+
41+
env:
42+
IMAGE_NAME: mcp-backend
43+
44+
steps:
45+
- name: Checkout repository
46+
- uses: actions/checkout@v4
47+
48+
- name: Login to GitHub Container Registry
49+
uses: docker/login-action@v3
50+
with:
51+
registry: ghcr.io
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Build Docker image
56+
run: |
57+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
58+
VERSION=${{ github.sha }}
59+
60+
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
61+
echo "VERSION=$VERSION" >> $GITHUB_ENV
62+
63+
docker build -t $IMAGE_ID:$VERSION -t $IMAGE_ID:latest .
64+
65+
- name: Push Docker image
66+
run: |
67+
docker push $IMAGE_ID:$VERSION
68+
docker push $IMAGE_ID:latest

0 commit comments

Comments
 (0)