-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (65 loc) · 2.09 KB
/
pipeline.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
name: Pipeline CI
on:
push:
branches:
- main
- develop
- feat/deploy
permissions: write-all
env:
REGISTRY: ghcr.io
IMAGE_NAME: rafaellevissa/bank-webapp:latest
APP_NAME: react-relay-graphql
APP_PORT: 5173
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Installing Dependencies
run: npm install
- name: Create dotenv
run: echo "${{ secrets.ENV }}" | base64 --decode > .env
- run: npm run test
build:
runs-on: ubuntu-latest
needs: tests
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Github Registrey
if: success()
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create dotenv
run: echo "${{ secrets.ENV }}" | base64 --decode > .env
- name: Build image api
run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} .
- name: Publish image api
run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: EC2 Deployment
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
script: |-
docker container stop ${{ env.APP_NAME}} || true
docker container rm ${{ env.APP_NAME}} || true
docker login ${{ env.REGISTRY }} -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
docker run -d -p ${{ env.APP_PORT }}:${{ env.APP_PORT }} --restart=unless-stopped --name ${{ env.APP_NAME}} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}