Skip to content

Commit 0bd67d1

Browse files
authored
docker build and publish (#2)
* docker build and publish * github actions * dev
1 parent 90b7eca commit 0bd67d1

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
release:
9+
types: [ published ]
10+
11+
jobs:
12+
13+
build-test:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Build Docker image
21+
run: |
22+
docker build -f ./docker/Dockerfile -t tradenode:test .
23+
24+
- name: Test Docker image
25+
run: |
26+
docker run --rm tradenode:test > /tmp/test.log || true
27+
28+
if grep -q "CONNECTING TO MONGODB" /tmp/test.log; then
29+
echo "Build successful"
30+
else
31+
echo "Build failed!"
32+
exit 1
33+
fi
34+
35+
push-to-ghcr:
36+
runs-on: ubuntu-latest
37+
if: github.ref == 'refs/heads/main'
38+
needs: build-test
39+
permissions:
40+
contents: read
41+
packages: write
42+
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v4
46+
47+
- name: Log in to GitHub Container Registry
48+
uses: docker/login-action@v3
49+
with:
50+
registry: ghcr.io
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Extract metadata for Docker
55+
id: meta
56+
uses: docker/metadata-action@v5
57+
with:
58+
images: ghcr.io/${{ github.repository }}
59+
60+
- name: Build and push
61+
uses: docker/build-push-action@v6
62+
with:
63+
context: .
64+
platforms: linux/amd64,linux/arm64
65+
file: ./docker/Dockerfile
66+
push: true
67+
tags: |
68+
ghcr.io/${{ github.repository }}:latest
69+
ghcr.io/${{ github.repository }}:${{ github.sha }}
70+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)