-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (69 loc) · 2.04 KB
/
docker-image.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Docker Image CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
jobs:
# test:
# name: Jest Tests
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
# - name: Set up NodeJS
# uses: actions/setup-node@v1
# with:
# node-version: 20
# - name: Install all dependencies
# run: npm install
# - name: Run Tests
# run: npm test
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Docker auth
uses: docker/login-action@v1
with:
username: ${{ env.DOCKER_USER }}
password: ${{ env.DOCKER_PASSWORD }}
- name: Build and push Docker Image
uses: docker/build-push-action@v2
with:
context: ./
push: true
dockerfile: ./Dockerfile
tags: jaderodev/aup-backend:latest
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Docker auth
uses: docker/login-action@v1
with:
username: ${{ env.DOCKER_USER }}
password: ${{ env.DOCKER_PASSWORD }}
- name: Set permissions for private key
run: |
echo "${{ secrets.AWS_PRIVATE_KEY }}" > key.pem
chmod 600 key.pem
- name: Move to project folder
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'cd backend/ && sudo docker compose down'
- name: Remove old image
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'sudo docker image rm -f backend-aup-backend:latest'
- name: Run new containers
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'cd backend/ && git pull && sudo docker compose up -d'