Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Build and Push Docker Image

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
release:
types: [ published ]

jobs:

build-test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build Docker image
run: |
docker build -f ./docker/Dockerfile -t tradenode:test .

- name: Test Docker image
run: |
docker run --rm tradenode:test > /tmp/test.log || true

if grep -q "CONNECTING TO MONGODB" /tmp/test.log; then
echo "Build successful"
else
echo "Build failed!"
exit 1
fi

push-to-ghcr:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: build-test
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
file: ./docker/Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}