Skip to content

Commit 947de70

Browse files
authored
Create deployment.yml
1 parent 6c928c6 commit 947de70

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

.github/workflows/deployment.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Docker CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v2
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v2
19+
20+
- name: Log in to Docker Hub
21+
uses: docker/login-action@v2
22+
with:
23+
username: ${{ secrets.DOCKER_USERNAME }}
24+
password: ${{ secrets.DOCKER_PASSWORD }}
25+
26+
- name: Build and push Docker image
27+
uses: docker/build-push-action@v4
28+
with:
29+
context: .
30+
push: true
31+
tags: ${{ secrets.DOCKER_USERNAME }}/bot-app:latest
32+
33+
deploy:
34+
runs-on: ubuntu-latest
35+
needs: build
36+
37+
steps:
38+
- name: SSH to remote server and deploy
39+
uses: appleboy/ssh-action@v0.1.5
40+
with:
41+
host: ${{ secrets.REMOTE_HOST }}
42+
username: ${{ secrets.REMOTE_USER }}
43+
key: ${{ secrets.REMOTE_SSH_KEY }}
44+
script: |
45+
docker pull ${{ secrets.DOCKER_USERNAME }}/my-app:latest
46+
docker stop my-app || true
47+
docker rm my-app || true
48+
docker run -d --name bot-app -p ${{ secrets.PORT }}:${{ secrets.REMOTE_USER }} ${{ secrets.DOCKER_USERNAME }}/bot-app:latest --tg.token='${{ secrets.TG_BOT_TOKEN }}'

0 commit comments

Comments
 (0)