generated from lapig-ufg/plataform-base
-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (82 loc) · 4.06 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Build and Deploy in DockerHUB Server Araticum
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 }}
START_TIME: ${{ steps.creat_env.outputs.START_TIME }}
LAST_COMMIT_HASH: ${{ steps.creat_env.outputs.LAST_COMMIT_HASH }}
LAPIG_AUTHOR_NAME: ${{ steps.creat_env.outputs.LAPIG_AUTHOR_NAME }}
LAPIG_AUTHOR_EMAIL: ${{ steps.creat_env.outputs.LAPIG_AUTHOR_EMAIL }}
LAPIG_AUTHOR_DATE: ${{ steps.creat_env.outputs.LAPIG_AUTHOR_DATE }}
LAPIG_PROJECT_NAME: ${{ steps.creat_env.outputs.LAPIG_PROJECT_NAME }}
LAPIG_COMMIT_DATE: ${{ steps.creat_env.outputs.LAPIG_COMMIT_DATE }}
CREATE_STATUS: ${{steps.deploy_container.outputs.CREATE_STATUS}}
DELETE_STATUS: ${{steps.delete_container.outputs.DELETE_STATUS}}
START_STATUS: ${{steps.start_container.outputs.START_STATUS}}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Define a variável application_name
id: creat_env
run: |
echo "START_TIME=$(date -u +%s)" >> "$GITHUB_OUTPUT"
echo "DOCKER_PATH=prod" >> $GITHUB_ENV
echo "DOCKER_PATH=prod" >> $GITHUB_OUTPUT
repo_full_name=$GITHUB_REPOSITORY
repo_name=${repo_full_name##*/}
echo "Nome do repositório: $repo_name"
echo "application_name=app_araticum" >> $GITHUB_ENV
echo "APPLICATION_NAME=app_araticum" >> $GITHUB_OUTPUT
echo "LAST_COMMIT_HASH=$(git log --pretty=format:%h -n 1)" >> $GITHUB_ENV
echo "LAST_COMMIT_HASH=$(git log --pretty=format:%h -n 1)" >> "$GITHUB_OUTPUT"
echo "LAPIG_AUTHOR_NAME=$(git show -s --pretty=%an)" >> "$GITHUB_OUTPUT"
echo "LAPIG_AUTHOR_EMAIL=$(git show -s --pretty=%ae)" >> "$GITHUB_OUTPUT"
echo "LAPIG_AUTHOR_DATE=$(git log -1 --format=%cd --date=local)" >> "$GITHUB_OUTPUT"
echo "LAPIG_PROJECT_NAME=$repo_name" >> "$GITHUB_OUTPUT"
echo "LAPIG_COMMIT_DATE=$(git show -s --format=%ci)" >> "$GITHUB_OUTPUT"
echo "NODE_OPTIONS=--max-old-space-size=8096" >> $GITHUB_ENV
- name: Create version.json
run: echo "{\"commitId\":\"$LAST_COMMIT_HASH\"}" > version.json
- name: Configurar Node.js
uses: actions/setup-node@v2
with:
node-version: '16.4.2'
- name: Build Server and client
run: |
npm set progress=false
cd ${{ github.workspace }}/src/server && npm install
cd ${{ github.workspace }}/src/client && npm install
npm install -g @angular/cli@12.2.16
cd ${{ github.workspace }}/src/client && ng build --stats-json --source-map=false --no-progress
- name: Build Docker
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
- name: Remove image locally
run: |
docker rmi lapig/$application_name:${DOCKER_PATH}_${LAST_COMMIT_HASH}
docker rmi lapig/$application_name:${DOCKER_PATH}_latest
deploy:
needs: build
runs-on: self-hosted
steps:
- name: Load env
run: |
echo "application_name=${{needs.build.outputs.APPLICATION_NAME}}" >> $GITHUB_ENV
echo "DOCKER_PATH=${{needs.build.outputs.DOCKER_PATH}}" >> $GITHUB_ENV
- name: Pull Image on Server
run: |
docker pull lapig/$application_name:${DOCKER_PATH}_latest
- name: Restart app
run: /compose/resetapp.sh --title 'Plataforma Araticum' $application_name