Skip to content

Commit 8509c0f

Browse files
fix: Refactor deployment workflow to include SSH checks and streamline environment preparation
1 parent f614746 commit 8509c0f

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

.github/workflows/deploy_docker_to_aws.yml

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,22 @@ jobs:
1717
steps:
1818
- name: Checkout Code
1919
uses: actions/checkout@v4
20-
21-
- name: Print selected URL
22-
run: echo "Will deploy to https://client.${{ vars.EC2_PUBLIC_IP }}.nip.io"
23-
24-
- name: Copy Docker Compose File From Repo to VM Host
20+
- name: Test SSH, disk space & Docker registry
21+
uses: appleboy/ssh-action@v1.0.3
22+
with:
23+
host: ${{ vars.EC2_PUBLIC_IP }}
24+
username: ${{ vars.AWS_EC2_USER }}
25+
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
26+
script: |
27+
set -e
28+
echo "Testing disk space:"
29+
df -h /
30+
echo "Testing Docker:"
31+
docker ps
32+
echo "Testing Docker registry login:"
33+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
34+
echo "All initial checks passed."
35+
- name: Copy Docker Compose File From Repo to the EC2 Instance
2536
uses: appleboy/scp-action@v0.1.7
2637
with:
2738
host: ${{ vars.EC2_PUBLIC_IP }}
@@ -30,18 +41,14 @@ jobs:
3041
source: "./docker-compose.prod.yml"
3142
target: /home/${{ vars.AWS_EC2_USER }}
3243

33-
- name: Log copy success
34-
run: |
35-
echo "Docker Compose file copied to VM host at /home/${{ vars.AWS_EC2_USER }}/docker-compose.prod.yml"
36-
3744
- name: Get latest tag (or use 1.0-alpha as fallback)
3845
id: get_tag
3946
run: |
4047
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "1.0-alpha")
4148
echo "tag=$TAG" >> $GITHUB_OUTPUT
4249
echo "Latest tag is: $TAG"
4350
44-
- name: Prepare Environment File
51+
- name: Prepare Environment File (.env.prod)
4552
uses: appleboy/ssh-action@v1.0.3
4653
with:
4754
host: ${{ vars.EC2_PUBLIC_IP }}
@@ -99,9 +106,9 @@ jobs:
99106
100107
chmod 600 .env.prod
101108
echo ".env.prod file created."
102-
- name: SSH to VM and Execute Docker-Compose Up
109+
- name: SSH to the EC2 Instance and Start Docker Compose
103110
uses: appleboy/ssh-action@v1.0.3
104-
timeout-minutes: 20
111+
timeout-minutes: 10
105112
with:
106113
host: ${{ vars.EC2_PUBLIC_IP }}
107114
username: ${{ vars.AWS_EC2_USER }}
@@ -119,19 +126,4 @@ jobs:
119126
echo "------------ Recent logs ----------------"
120127
docker compose -f docker-compose.prod.yml logs --tail=40
121128
exit 1
122-
fi
123-
124-
- name: SSH to VM and Clean Up Old Docker Images and Volumes
125-
uses: appleboy/ssh-action@v1.0.3
126-
with:
127-
host: ${{ vars.EC2_PUBLIC_IP }}
128-
username: ${{ vars.AWS_EC2_USER }}
129-
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
130-
script: |
131-
set -e
132-
cd /home/${{ vars.AWS_EC2_USER }}
133-
echo "Pruning unused Docker images and volumes..."
134-
docker image prune -af
135-
docker volume prune -f
136-
docker system prune -af
137-
echo "Cleanup complete."
129+
fi

0 commit comments

Comments
 (0)