Skip to content

Commit b5cd729

Browse files
committed
Added ssh into EC2 for github actions
1 parent 7335f08 commit b5cd729

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

.github/workflows/cd.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Deploy on EC2-Instance
33
on:
44
workflow_run:
55
workflows: ["Docker Image CI"]
6-
branches: ["deploy"]
76
types: [completed]
87

98
jobs:
@@ -19,4 +18,4 @@ jobs:
1918
host: ${{secrets.HOST_DNS}}
2019
username: ${{secrets.EC2_USER}}
2120
key: ${{secrets.EC2_SSH_KEY}}
22-
21+
-

.github/workflows/ci.yml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,45 @@ on:
55
branches: ["deploy"]
66

77
jobs:
8-
8+
env:
9+
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
10+
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
11+
912
build:
10-
1113
runs-on: ubuntu-latest
1214

1315
steps:
1416
- uses: actions/checkout@v3
1517

16-
- name: Login Dockerhub
17-
env:
18-
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
19-
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
18+
- name: Login Dockerhub
2019
run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
2120

2221
- name: Build Docker Container
2322
uses: docker/build-push-action@v6
2423
with:
2524
context: ./Frontend
2625
tags: thomastejedor/quiz-slayer-env:latest
26+
push: true
2727
secrets: |
2828
"PRIVATE_KEY=${{secrets.PRIVATE_SSL_KEY}}"
2929
"SSL_CERT=${{secrets.SSL_CERT}}"
30-
30+
deploy:
31+
name: Deploy to EC2
32+
runs-on: ubuntu-latest
33+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
34+
steps:
35+
36+
- name: Deploy via SSH
37+
uses: appleboy/ssh-action@v0.1.10
38+
with:
39+
host: ${{secrets.HOST_DNS}}
40+
username: ${{secrets.EC2_USER}}
41+
key: ${{secrets.EC2_SSH_KEY}}
42+
43+
- name: Pull Docker image
44+
run: sudo docker pull thomastejedor/quiz-slayer-env:latest
45+
- name: Delete old docker container
46+
run: sudo docker rm -f cicd-pipeline-container || true
47+
- name: Run Docker Container
48+
run: sudo docker run -itd -p 80:80 -p 443:443 cicd-pipeline-container thomastejedor/quiz-slayer-env
3149

0 commit comments

Comments
 (0)