Repository navigation
65 lines (52 loc) · 1.69 KB
/
Copy pathnodejs-deploy.yml
File metadata and controls
65 lines (52 loc) · 1.69 KB
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
name: Node.js Service — CI/CD
on:
push:
branches: [main]
paths:
- 'projects/05-automation/01-nodejs-service-deployment/**'
- '.github/workflows/nodejs-deploy.yml'
jobs:
test:
name: Testes e Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: projects/05-automation/01-nodejs-service-deployment/app
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: projects/05-automation/01-nodejs-service-deployment/app/package-lock.json
- name: Instalar dependências
run: npm ci
- name: Rodar testes
run: npm test
deploy:
name: Deploy via Ansible
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Configurar SSH Agent
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.EC2_NODE_SSH_KEY }}
- name: Adicionar host ao known_hosts
run: ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts
- name: Instalar Ansible
run: pip install ansible
- name: Criar inventário dinâmico
run: |
cat > projects/05-automation/01-nodejs-service-deployment/config/inventory/hosts.yml << INVENTORY
all:
hosts:
nodejs_server:
ansible_host: ${{ secrets.EC2_HOST }}
ansible_user: ${{ secrets.EC2_USER }}
INVENTORY
- name: Executar playbook Ansible
run: |
cd projects/05-automation/01-nodejs-service-deployment/config
ansible-playbook node_service.yml --tags app