generated from lapig-ufg/plataform-base
-
Notifications
You must be signed in to change notification settings - Fork 1
76 lines (65 loc) · 2.64 KB
/
prod.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
name: Build and Deploy in Production Server AGROTÓXICOS
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
outputs:
APPLICATION_NAME: ${{ steps.creat_env.outputs.APPLICATION_NAME }}
DOCKER_PATH: ${{ steps.creat_env.outputs.DOCKER_PATH }}
LAST_COMMIT_HASH: ${{ steps.creat_env.outputs.LAST_COMMIT_HASH }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Define environment variables
id: creat_env
run: |
# Função para definir variáveis no GITHUB_ENV e GITHUB_OUTPUT
set_var() {
echo "$1=$2" >> $GITHUB_ENV
echo "$1=$2" >> $GITHUB_OUTPUT
}
# Defina as variáveis
set_var "DOCKER_PATH" "prod"
set_var "APPLICATION_NAME" "app_agrotoxico"
set_var "LAST_COMMIT_HASH" "$(git log --pretty=format:%h -n 1)"
- name: Create version.json
run: echo "{\"commitId\":\"$LAST_COMMIT_HASH\"}" > version.json
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16.4.2'
- name: Build Server and Client
run: |
export NODE_OPTIONS=--max-old-space-size=8096
npm set progress=false
cd ${{ github.workspace }}/src/server && npm install
cd ${{ github.workspace }}/src/client && npm install
npm install -g @angular/[email protected]
cd ${{ github.workspace }}/src/client && ng build --stats-json --source-map=false --no-progress
- name: Build Docker image
run: |
docker build -t lapig/$APPLICATION_NAME:${DOCKER_PATH}_${LAST_COMMIT_HASH} \
-t lapig/$APPLICATION_NAME:${DOCKER_PATH}_latest \
-f docker/$DOCKER_PATH/Dockerfile . --no-cache
- name: Login to Docker Registry
run: echo "${{ secrets.DOCKERHUB_PASS }}" | docker login -u "lapig" --password-stdin
- name: Push Image to Registry
run: |
docker push lapig/$APPLICATION_NAME:${DOCKER_PATH}_${LAST_COMMIT_HASH}
docker push lapig/$APPLICATION_NAME:${DOCKER_PATH}_latest
deploy:
needs: build
runs-on: self-hosted
steps:
- name: Pull Image on Server
run: |
docker pull lapig/${{ needs.build.outputs.APPLICATION_NAME }}:${{ needs.build.outputs.DOCKER_PATH }}_latest
- name: Restart Application
run: |
/compose/resetapp.sh --title "Plataforma Agrotóxicos" \
--github "https://github.com/${{ github.repository }}" \
--commit "${{ needs.build.outputs.LAST_COMMIT_HASH }}" \
${{ needs.build.outputs.APPLICATION_NAME }}