diff --git a/.github/workflows/docker-image-pr.yml b/.github/workflows/docker-image-pr.yml new file mode 100644 index 000000000..301232411 --- /dev/null +++ b/.github/workflows/docker-image-pr.yml @@ -0,0 +1,82 @@ +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 "AdminEmail=admin@example.com" \ + -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 "CompanyEmail=info@company.com" + + - 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 + curl -s http://localhost:8080 && echo "Application is up!" && break + echo "Retrying in 3 seconds..." + sleep 3 + done + + - name: Stop and remove the container + run: | + docker stop grandnode2-container + docker rm grandnode2-container