|
7 | 7 |
|
8 | 8 | jobs:
|
9 | 9 | build-and-deploy:
|
10 |
| - # Run on your self-hosted runner so it has Docker |
11 | 10 | runs-on: self-hosted
|
12 |
| - # Alternatively: runs-on: [self-hosted, linux] |
13 | 11 |
|
14 | 12 | steps:
|
15 | 13 | - name: Check out repository
|
16 | 14 | uses: actions/checkout@v3
|
17 | 15 |
|
18 |
| - # Create the google-services.json file from the secret. |
19 | 16 | - name: Create google-services.json
|
20 | 17 | run: |
|
21 |
| - # Use printf to preserve formatting/newlines |
| 18 | + # Use printf to preserve formatting and newlines |
22 | 19 | printf "%s" "${{ secrets.GOOGLE_SERVICES_JSON }}" > google-services.json
|
23 | 20 |
|
24 |
| - # Optional: Create .env file from a secret (if needed) |
25 | 21 | - name: Create .env file
|
26 | 22 | run: |
|
27 | 23 | printf "%s" "${{ secrets.ENV_FILE_CONTENT }}" > .env
|
28 | 24 |
|
29 |
| - # Debug step: check file size so we can verify something was written. |
| 25 | + # Debug: Check file size |
30 | 26 | - name: Check google-services.json file size
|
31 | 27 | run: wc -c google-services.json
|
32 | 28 |
|
| 29 | + # Debug: Validate JSON syntax (this will fail if the JSON is invalid) |
| 30 | + - name: Validate google-services.json |
| 31 | + run: node -e "JSON.parse(require('fs').readFileSync('google-services.json','utf8'))" |
| 32 | + |
33 | 33 | - name: Build Docker image
|
34 |
| - run: | |
35 |
| - docker build -t codebuilder-webapp:latest . |
| 34 | + run: docker build -t codebuilder-webapp:latest . |
36 | 35 |
|
37 | 36 | - name: Stop and remove old container (if running)
|
38 | 37 | run: |
|
39 |
| - # Find any running container based on the image |
40 | 38 | OLD_CONTAINER_ID=$(docker ps -q --filter ancestor=codebuilder-webapp:latest)
|
41 | 39 | if [ -n "$OLD_CONTAINER_ID" ]; then
|
42 | 40 | echo "Stopping and removing container $OLD_CONTAINER_ID..."
|
|
47 | 45 | fi
|
48 | 46 |
|
49 | 47 | - name: Start new container
|
50 |
| - run: | |
51 |
| - docker run -d --network host -p 3000:3000 --name codebuilder-webapp codebuilder-webapp:latest |
| 48 | + run: docker run -d --network host -p 3000:3000 --name codebuilder-webapp codebuilder-webapp:latest |
0 commit comments