-
Notifications
You must be signed in to change notification settings - Fork 459
90 lines (77 loc) · 2.84 KB
/
docker-image-pr.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
name: Docker Image CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build the Docker image
run: docker build . --file Dockerfile --tag grandnode2:pr-latest
- name: Start MongoDB container
run: |
docker run --name mongodb-container -d -p 27017:27017 mongo:latest
- name: Wait for MongoDB to be ready
run: |
echo "Waiting for MongoDB to start..."
for i in {1..10}; do
nc -z localhost 27017 && echo "MongoDB is up" && break
echo "Retrying in 3 seconds..."
sleep 3
done
- name: List Docker images
run: docker images
- name: Run the application container
run: |
docker run --name grandnode2-container -d -p 8080:8080 --link mongodb-container:mongo grandnode2:pr-latest
- name: Wait for the application to be ready
run: |
echo "Waiting for the application to start..."
for i in {1..10}; do
curl -s http://localhost:8080 && echo "Application is up!" && break
echo "Retrying in 3 seconds..."
sleep 3
done
- name: Trigger the installer via POST request
run: |
echo "Running installation with form-data..."
curl -X POST http://localhost:8080/install \
-H "Content-Type: multipart/form-data" \
-F "[email protected]" \
-F "AdminPassword=SecurePassword123" \
-F "ConfirmPassword=SecurePassword123" \
-F "DataProvider=0" \
-F "MongoDBServerName=mongo" \
-F "MongoDBDatabaseName=grandnode" \
-F "InstallSampleData=true" \
-F "CompanyName=My Company" \
-F "CompanyAddress=123 Main St" \
-F "CompanyPhoneNumber=1234567890" \
-F "[email protected]"
- name: Restart the application container
run: |
docker restart grandnode2-container
- name: Test HTTP response after installation
run: |
echo "Waiting for the application to start..."
for i in {1..10}; do
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "error")
if [ "$RESPONSE" = "200" ]; then
echo "Application is up with HTTP 200 response!"
exit 0
elif [ "$RESPONSE" = "error" ]; then
echo "Curl encountered an error. Retrying in 3 seconds..."
else
echo "Received HTTP response code: $RESPONSE. Retrying in 3 seconds..."
fi
sleep 3
done
echo "Application did not start successfully. Final response code: $RESPONSE"
exit 1
- name: Stop and remove the container
run: |
docker stop grandnode2-container
docker rm grandnode2-container