-
Notifications
You must be signed in to change notification settings - Fork 0
51 lines (42 loc) · 1.61 KB
/
deploy-docker.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
name: Deploy Next.js Docker App
on:
push:
branches:
- main
jobs:
build-and-deploy:
# Run on your self-hosted runner so it has Docker
runs-on: self-hosted
# Alternatively: runs-on: [self-hosted, linux]
steps:
- name: Check out repository
uses: actions/checkout@v3
# Create the google-services.json file from the secret.
- name: Create google-services.json
run: |
# Use printf to preserve formatting/newlines
printf "%s" "${{ secrets.GOOGLE_SERVICES_JSON }}" > google-services.json
# Optional: Create .env file from a secret (if needed)
- name: Create .env file
run: |
printf "%s" "${{ secrets.ENV_FILE_CONTENT }}" > .env
# Debug step: check file size so we can verify something was written.
- name: Check google-services.json file size
run: wc -c google-services.json
- name: Build Docker image
run: |
docker build -t codebuilder-webapp:latest .
- name: Stop and remove old container (if running)
run: |
# Find any running container based on the image
OLD_CONTAINER_ID=$(docker ps -q --filter ancestor=codebuilder-webapp:latest)
if [ -n "$OLD_CONTAINER_ID" ]; then
echo "Stopping and removing container $OLD_CONTAINER_ID..."
docker stop $OLD_CONTAINER_ID
docker rm $OLD_CONTAINER_ID
else
echo "No old container found."
fi
- name: Start new container
run: |
docker run -d --network host -p 3000:3000 --name codebuilder-webapp codebuilder-webapp:latest