forked from Eleven-Trading/TradeNote
-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (109 loc) · 3.48 KB
/
docker-publish.yml
File metadata and controls
131 lines (109 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Build and Push Docker Image
on:
push:
branches: [ main ]
paths-ignore:
- 'brokers/**'
- 'README.md'
- '.gitignore'
- 'Makefile'
pull_request:
branches: [ main ]
paths-ignore:
- 'brokers/**'
- 'README.md'
- '.gitignore'
- 'Makefile'
release:
types: [ published ]
workflow_dispatch:
inputs:
manual_push:
description: 'Set to "yes" to push tag :test image to GHCR for testing before merging to main'
required: false
default: 'no'
type: choice
options:
- 'no'
- 'yes'
jobs:
build-local:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: npm run build
run: |
make node-build
- name: npm run preview
run: |
npm run preview -- --port 8080 & sleep 10; curl -f http://localhost:8080 || exit 1
build-test:
runs-on: ubuntu-latest
needs: build-local
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
# Run if on main branch, or if manual_push is yes from workflow_dispatch
if: >-
(github.ref == 'refs/heads/main') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.manual_push == 'yes')
needs: build-test
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# 👆 This is needed ARM emulation on AMD64 runner
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 👆 This is need for QEMU to work
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set lowercase repository name
run: |
echo "LOWERCASE_REPO=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Set IMAGE_TAG for build-test
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.manual_push }}" = "yes" ]; then
echo "IMAGE_TAG=test" >> $GITHUB_ENV
elif [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
fi
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.LOWERCASE_REPO }}
- 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/${{ env.LOWERCASE_REPO }}:${{ env.IMAGE_TAG }}
ghcr.io/${{ env.LOWERCASE_REPO }}:${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}