-
Notifications
You must be signed in to change notification settings - Fork 91
169 lines (144 loc) · 5.91 KB
/
node.yml
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: node
on:
push:
branches:
- "master"
pull_request:
branches:
- "master"
jobs:
test:
runs-on: ubuntu-latest
services:
redis:
image: redis:6
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build test image
uses: docker/build-push-action@v6
with:
platforms: linux/amd64
target: dev
context: .
load: true
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/blot
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/blot,mode=max
tags: ghcr.io/${{ github.repository_owner }}/blot:test-${{ github.sha }}
- name: Run tests
env:
BLOT_STRIPE_KEY: ${{ secrets.BLOT_STRIPE_KEY }}
BLOT_STRIPE_SECRET: ${{ secrets.BLOT_STRIPE_SECRET }}
BLOT_STRIPE_PRODUCT: ${{ secrets.BLOT_STRIPE_PRODUCT }}
run: |
docker run --rm \
--network name=${{ job.services.redis.network }} \
-e BLOT_REDIS_HOST=redis \
-e BLOT_STRIPE_KEY=$BLOT_STRIPE_KEY \
-e BLOT_STRIPE_SECRET=$BLOT_STRIPE_SECRET \
-e BLOT_STRIPE_PRODUCT=$BLOT_STRIPE_PRODUCT \
-v ${{ github.workspace }}/app:/usr/src/app/app \
-v ${{ github.workspace }}/scripts:/usr/src/app/scripts \
-v ${{ github.workspace }}/config:/usr/src/app/config \
-v ${{ github.workspace }}/notes:/usr/src/app/notes \
-v ${{ github.workspace }}/todo.txt:/usr/src/app/todo.txt \
-v ${{ github.workspace }}/.git:/usr/src/app/.git \
-v ${{ github.workspace }}/tests:/usr/src/app/tests \
ghcr.io/${{ github.repository_owner }}/blot:test-${{ github.sha }} \
sh -c "node /usr/src/app/app/documentation/build/index.js --no-watch --skip-zip && node tests && npx depcheck --ignores=depcheck,nyc,nodemon,blessed-contrib,fontkit,text-to-svg --skip-missing"
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build production image
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
target: prod
context: .
push: true
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/blot
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/blot,mode=max
tags: ghcr.io/${{ github.repository_owner }}/blot:${{ github.sha }}
- name: Verify built-in health check
env:
IMAGE: ghcr.io/${{ github.repository_owner }}/blot:${{ github.sha }}
run: |
docker network create test_network
# Start a Redis container
redis_container_id=$(docker run -d --name test_redis --network test_network redis:latest)
# Ensure Redis started successfully
if [ -z "$redis_container_id" ]; then
echo "Failed to start the Redis container. Exiting..."
exit 1
fi
echo "Waiting for Redis ($redis_container_id) to become ready..."
timeout=30
interval=2
elapsed=0
while ! docker exec $redis_container_id redis-cli ping | grep -q PONG; do
if [ $elapsed -ge $timeout ]; then
echo "Redis did not become ready within $timeout seconds. Exiting..."
docker stop $redis_container_id
docker rm $redis_container_id
exit 1
fi
sleep $interval
elapsed=$((elapsed + interval))
done
echo "Redis is ready."
# Start the app container with Redis environment variables
container_id=$(docker run -d --network test_network --env BLOT_REDIS_HOST=test_redis -p 8080:8080 $IMAGE)
# Ensure the app container started successfully
if [ -z "$container_id" ]; then
echo "Failed to start the app container. Exiting..."
docker stop $redis_container_id
docker rm $redis_container_id
exit 1
fi
echo "Waiting for the app container ($container_id) to pass the built-in health check..."
# Wait for the app container's health status to become "healthy"
timeout=60
interval=5
elapsed=0
while [ "$(docker inspect --format='{{json .State.Health.Status}}' $container_id)" != '"healthy"' ]; do
if [ $elapsed -ge $timeout ]; then
echo "Health check failed: app container did not become healthy within $timeout seconds."
echo "Final log contents:"
docker exec $container_id cat /usr/src/app/data/logs/docker/app.log
docker stop $container_id
docker rm $container_id
docker stop $redis_container_id
docker rm $redis_container_id
exit 1
fi
sleep $interval
elapsed=$((elapsed + interval))
done
echo "App container passed the health check."
# Clean up
docker stop $container_id
docker rm $container_id
docker stop $redis_container_id
docker rm $redis_container_id