-
Notifications
You must be signed in to change notification settings - Fork 152
84 lines (77 loc) · 2.58 KB
/
ci-container-build.yaml
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
name: Container Image Build Test for PRs
env:
VERSION: ci-test # Used for docker tag
on:
push:
branches:
- main
- development
paths:
- 'backend/**'
- 'frontend/**'
- 'unstract/**'
- 'platform-service/**'
- 'x2text-service/**'
- 'worker/**'
- 'docker/dockerfiles/**'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- main
- development
paths:
- 'backend/**'
- 'frontend/**'
- 'unstract/**'
- 'platform-service/**'
- 'x2text-service/**'
- 'worker/**'
- 'docker/dockerfiles/**'
jobs:
build:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Container Build
working-directory: ./docker
run: |
docker compose -f docker-compose.build.yaml build
- name: Container Run
working-directory: ./docker
run: |
cp ../backend/sample.env ../backend/.env
cp ../platform-service/sample.env ../platform-service/.env
cp ../prompt-service/sample.env ../prompt-service/.env
cp ../worker/sample.env ../worker/.env
cp ../x2text-service/sample.env ../x2text-service/.env
cp sample.essentials.env essentials.env
cp sample.env .env
docker compose -f docker-compose.yaml up -d
sleep 10
docker compose -f docker-compose.yaml ps -a
# Get the names of exited containers
custom_format="{{.Name}}\t{{.Image}}\t{{.Service}}"
EXITED_CONTAINERS=$(docker compose -f docker-compose.yaml ps -a --filter status=exited --format "$custom_format")
line_count=$(echo "$EXITED_CONTAINERS" | wc -l)
if [ "$line_count" -gt 1 ]; then
echo "Exited Containers: $EXITED_CONTAINERS"
SERVICE=$(echo "$EXITED_CONTAINERS" | awk 'NR>0 {print $3}')
echo "Exited Services:"
echo "$SERVICE"
echo "There are exited containers."
# Print logs of exited containers
IFS=$'\n'
for SERVICE in $SERVICE; do
docker compose -f docker-compose.yaml logs "$SERVICE"
done
docker compose -f docker-compose.yaml down -v
exit 1
fi
docker compose -f docker-compose.yaml down -v