Skip to content

Commit

Permalink
Merge pull request #1 from lapig-ufg/update-camadas
Browse files Browse the repository at this point in the history
Update camadas
  • Loading branch information
jairomr authored Sep 2, 2023
2 parents 9623e22 + 3f3e75b commit b132f46
Show file tree
Hide file tree
Showing 147 changed files with 1,691 additions and 1,255 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This is a basic workflow to help you get started with Actions

name: docs

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v2
- run: pip install --upgrade pip && pip install install mkdocs-material && pip install mkdocs-minify-plugin
- run: git config user.name 'github-actions[bot]' && git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Publish docs
run: mkdocs gh-deploy --force
139 changes: 139 additions & 0 deletions .github/workflows/homol.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Build and Deploy in Homology Server

on:
push:
branches:
- develop

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Configurar Node.js
uses: actions/setup-node@v2
with:
node-version: '16.4.2'


- name: Define a variável application_name
run: |
echo "branch=${GITHUB_REF##*/}" >> $GITHUB_ENV
repo_full_name=$GITHUB_REPOSITORY
repo_name=${repo_full_name##*/}
echo "START_TIME=$(date -u +%s)" >> $GITHUB_ENV
echo "Nome do repositório: $repo_name"
echo "application_name=app_araticum" >> $GITHUB_ENV
echo "LAST_COMMIT_HASH=$(git log --pretty=format:%h -n 1)" >> $GITHUB_ENV
echo "LAPIG_AUTHOR_NAME=$(git show -s --pretty=%an)" >> $GITHUB_ENV
echo "LAPIG_AUTHOR_EMAIL=$(git show -s --pretty=%ae)" >> $GITHUB_ENV
echo "LAPIG_AUTHOR_DATE=$(git log -1 --format=%cd --date=local)" >> $GITHUB_ENV
echo "LAPIG_PROJECT_NAME=$(git config --local remote.origin.url)" >> $GITHUB_ENV
echo "LAPIG_LAST_COMMIT=$(git show --summary | grep 'commit' | awk '{print $2}')" >> $GITHUB_ENV
echo "LAPIG_COMMIT_COMMENT=$(git log -1 --pretty=%B)" >> $GITHUB_ENV
echo "LAPIG_COMMIT_DATE=$(git show -s --format=%ci)" >> $GITHUB_ENV
echo "LAPIG_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV
echo "NODE_OPTIONS=--max-old-space-size=8096" >> $GITHUB_ENV
- name: Use Git outputs
run: |
echo "Author Name: $LAPIG_AUTHOR_NAME"
echo "Author Email: $LAPIG_AUTHOR_EMAIL"
echo "Author Date: $LAPIG_AUTHOR_DATE"
echo "Project Name: $LAPIG_PROJECT_NAME"
echo "Last Commit: $LAPIG_LAST_COMMIT"
echo "Commit Comment: $LAPIG_COMMIT_COMMENT"
echo "Commit Date: $LAPIG_COMMIT_DATE"
echo "Branch Name: $LAPIG_BRANCH_NAME"
- name: Create version.json
run: echo '{"commitId":"$LAST_COMMIT_HASH"}' > version.json

- name: Determine branch
id: get_branch
run: echo "::set-output name=branch::${GITHUB_REF##*/}"

- name: Build Server and client
run: |
npm set progress=false
cd ${{ github.workspace }}/src/server && npm install
cd ${{ github.workspace }}/src/client && npm install
cd ${{ github.workspace }}/src/client && ng build --stats-json --source-map=false --no-progress
- name: Validate and Build
run: |
git pull origin develop
docker build -t ${{secrets.REGISTRYHOMOL}}/$application_name:${LAST_COMMIT_HASH} -t ${{secrets.REGISTRYHOMOL}}/$application_name:latest -f docker/homologation/Dockerfile . --no-cache
- name: Login to Docker Registry
run: echo "${{ secrets.HARBOR_PASS }}" | docker login -u "${{ secrets.HARBOR_USER }}" --password-stdin "${{ secrets.URL_PRIVATE_REGISTRY }}"

- name: Push Image to Registry
run: |
docker push ${{secrets.REGISTRYHOMOL}}/$application_name:${LAST_COMMIT_HASH}
docker push ${{secrets.REGISTRYHOMOL}}/$application_name:latest
- name: Remove image locally
run: |
docker rmi ${{secrets.REGISTRYHOMOL}}/$application_name:${LAST_COMMIT_HASH}
docker rmi ${{secrets.REGISTRYHOMOL}}/$application_name:latest
- name: Add SSH key to known_hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -t rsa ${{secrets.SERVER_HOMOL_KNOWN}} >> ~/.ssh/known_hosts 2>/dev/null
chmod 644 ~/.ssh/known_hosts
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name: Pull Image on Server
run: |
ssh ${{secrets.SERVER_HOMOL_SSH}} "docker pull ${{secrets.REGISTRYHOMOL}}/$application_name:latest"
- name: Deploy Container
run: |
delete_status=$(ssh ${{secrets.SERVER_HOMOL_SSH}} "curl -v -X DELETE -w "%{http_code}" http://${{secrets.SERVER_HOMOL}}/containers/$application_name?force=true 2>/dev/null")
echo "Delete Status: $delete_status"
create_status=$(ssh ${{secrets.SERVER_HOMOL_SSH}} "curl -v -X POST -H 'Content-Type: application/json' -d @${{secrets.CONFIG_FILES}}$application_name.json -s -o /dev/null -w "%{http_code}" http://${{secrets.SERVER_HOMOL}}/containers/create?name=$application_name 2>/dev/null")
echo "Create Status: $create_status"
echo "CREATE_STATUS=$create_status" >> $GITHUB_ENV
echo "DELETE_STATUS=$delete_status" >> $GITHUB_ENV
- name: Start Container
run: |
start_status=$(ssh ${{secrets.SERVER_HOMOL_SSH}} "curl -v -X POST -s -o /dev/null -w "%{http_code}" http://${{secrets.SERVER_HOMOL}}/containers/$application_name/start 2>/dev/null")
echo "Start Status: $start_status"
echo "START_STATUS=$start_status" >> $GITHUB_ENV
- name: Send message to Telegram
run: |
end_time=$(date -u +%s)
echo "LAPIG_DURATION=$((end_time - START_TIME))" >> $GITHUB_ENV
curl -s -X POST "https://api.telegram.org/bot${TOKEN}/sendMessage" -d "chat_id=${CHAT_ID}" -d "parse_mode=markdown" -d "text=*Project*: *${LAPIG_PROJECT_NAME}*\n*Branch*: ${LAPIG_BRANCH_NAME}\n*Author*: *${LAPIG_AUTHOR_NAME}*\n*Author_Email*: *${LAPIG_AUTHOR_EMAIL}*\n*Commit_ID*: *${LAPIG_LAST_COMMIT}*\n*Message_Commit*: *${LAPIG_COMMIT_COMMENT}*\n*Date_Commit*: *${LAPIG_COMMIT_DATE}*\n*Duration*: *${LAPIG_DURATION}*'"
- name: Send message to Discord
run: |
if [[ "${{ job.status }}" == "success" && "$START_STATUS" == "204" && "$DELETE_STATUS" == "204" && "$CREATE_STATUS" == "201" ]]; then
echo "avatar_url='${{vars.LAPIG_SUCCESS}}'" >> $GITHUB_ENV
else
echo "avatar_url='${{vars.LAPIG_ERROR}}'" >> $GITHUB_ENV
fi
echo "discordDesc='Result: ${{ job.status }}\n Project: $LAPIG_PROJECT_NAME\n Commit: $LAPIG_LAST_COMMIT\n Author: $LAPIG_AUTHOR_NAME\n Author_Email: $LAPIG_AUTHOR_EMAIL\n Message: $LAPIG_COMMIT_COMMENT\n Date: $LAPIG_COMMIT_DATE\n Delete Status: $delete_status\n Create Status: $create_status\n Start Status: $start_status\n Duration: $LAPIG_DURATION seconds'" >> $GITHUB_ENV
echo "discordFooter='${{ github.workflow }} (#${{ github.run_number }})'" >> $GITHUB_ENV
echo "discordTitle='${{ github.workflow }} (build #${{ github.run_number }})'" >> $GITHUB_ENV
curl -H "Content-Type: application/json" -X POST -d '{"content": "${discordTitle}", "embeds": [ { "title": "${$discordTitle}", "description": "${discordDesc}", "footer": { "text": "${discordFooter}" } } ], "username": "GitHub Actions", "avatar_url": "${avatar_url}" }' https://discord.com/api/webhooks/${{ secrets.DISCORD_KEY }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*.tar.gz
*.rar

*.Jenkinsfile
*.Dockerfile

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
src/server/.env
Expand Down
79 changes: 33 additions & 46 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
node {

node {
load "$JENKINS_HOME/.envvars"
def exists=fileExists "src/server/package-lock.json"
def exists2=fileExists "src/client/package-lock.json"
def application_name= "app_araticum"
def NODE_VERSION= "14.16.0"

stage('Checkout') {
git branch: 'develop',
git branch: 'main',
url: 'https://github.com/lapig-ufg/restauracao-araticum.git'
}
stage('Validate') {
sh 'git pull origin develop'
sh 'git pull origin main'

}
stage('SonarQube analysis') {

def scannerHome = tool 'sonarqube-scanner';
withSonarQubeEnv("sonarqube") {
sh "${tool("sonarqube-scanner")}/bin/sonar-scanner \
-Dsonar.projectKey=araticum \
-Dsonar.projectKey=agrotoxicos\
-Dsonar.sources=. \
-Dsonar.css.node=. \
-Dsonar.host.url=$SonarUrl \
Expand All @@ -34,28 +33,17 @@
//BUILD APPLICATION
echo "Build main site distribution"
sh "npm set progress=false"
if (exists) {
echo 'Yes'
sh "cd src/server && npm ci"
} else {
echo 'No'
sh "cd src/server && npm install"
}
if (exists2) {
echo 'Yes'
sh "cd src/client && npm ci"
} else {
echo 'No'
sh "cd src/client && npm install"
}

sh "cd src/server && npm install"
sh "cd src/client && npm install"


//VERIFY IF BUILD IS COMPLETE AND NOTIFY IN DISCORD ABOUT OF THE RESULT
sh "export NODE_OPTIONS=--max-old-space-size=8096"
def status = sh(returnStatus: true, script: "cd src/client && ng build --stats-json --source-map=false --no-progress")
if (status != 0) {
echo "FAILED BUILD!"
currentBuild.result = 'FAILED'
def discordImageSuccess = 'https://www.jenkins.io/images/logos/formal/256.png'
def discordImageSuccess = 'https://www.jenkins.io/images/logos/formal/256.png'
def discordImageError = 'https://www.jenkins.io/images/logos/fire/256.png'

def Author_Name=sh(script: "git show -s --pretty=%an", returnStdout: true).trim()
Expand Down Expand Up @@ -92,54 +80,53 @@
autoCancelled = true
error('Aborting the build.')
}

}
}
stage('Building Image') {
dockerImage = docker.build registryhomol + "/$application_name:$BUILD_NUMBER"
dockerImage = docker.build registryprod + "/$application_name:$BUILD_NUMBER", "--build-arg --no-cache -f Dockerfile ."
}
stage('Push Image to Registry') {

docker.withRegistry( "$Url_Private_Registry", "$registryCredential" ) {
dockerImage.push("${env.BUILD_NUMBER}")
dockerImage.push("latest")

}

}
stage('Removing image Locally') {
sh "docker rmi $registryhomol/$application_name:$BUILD_NUMBER"
sh "docker rmi $registryhomol/$application_name:latest"
sh "docker rmi $registryprod/$application_name:$BUILD_NUMBER"
sh "docker rmi $registryprod/$application_name:latest"
}

stage ('Pull imagem on DEV') {
stage ('Pull imagem on PROD') {
sshagent(credentials : ['KEY_FULL']) {
sh "$SERVER_HOMOL_SSH 'docker pull $registryhomol/$application_name:latest'"
sh "$SERVER_PROD_SSH 'docker pull $registryprod/$application_name:latest'"
}

}
stage('Deploy container on PROD') {

configFileProvider([configFile(fileId: "$File_Json_Id_ARATICUM_PROD", targetLocation: 'container-araticum-deploy-prod.json')]) {

stage('Deploy container on DEV') {

configFileProvider([configFile(fileId: "$File_Json_Id_ARATICUM_HOMOL", targetLocation: 'container-araticum-deploy-homol.json')]) {

def url = "http://$SERVER_HOMOL/containers/$application_name?force=true"
def url = "http://$SERVER_PROD/containers/$application_name?force=true"
def response = sh(script: "curl -v -X DELETE $url", returnStdout: true).trim()
echo response

url = "http://$SERVER_HOMOL/containers/create?name=$application_name"
response = sh(script: "curl -v -X POST -H 'Content-Type: application/json' -d @container-araticum-deploy-homol.json -s $url", returnStdout: true).trim()
url = "http://$SERVER_PROD/containers/create?name=$application_name"
response = sh(script: "curl -v -X POST -H 'Content-Type: application/json' -d @container-araticum-deploy-prod.json -s $url", returnStdout: true).trim()
echo response
}

}
stage('Start container on DEV') {
stage('Start container on PROD') {

final String url = "http://$SERVER_HOMOL/containers/$application_name/start"
final String url = "http://$SERVER_PROD/containers/$application_name/start"
final String response = sh(script: "curl -v -X POST -s $url", returnStdout: true).trim()
echo response


}
stage('Send message to Discord') {

Expand Down Expand Up @@ -180,7 +167,7 @@
thumbnail: 'SUCCESS'.equals(currentBuild.currentResult) ? discordImageSuccess : discordImageError

}

stage('Send message to Telegram') {

def Author_Name=sh(script: "git show -s --pretty=%an", returnStdout: true).trim()
Expand All @@ -198,5 +185,5 @@
""")
}
}

}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Platform Restauração Araticum


A Articulação pela Restauração do Cerrado é uma rede colaborativa e multisetorial, que visa atuar
como uma coalizão cujo objetivo é promover a restauração em larga escala do Bioma.
17 changes: 17 additions & 0 deletions docker/homologation/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM registry.lapig.iesa.ufg.br/lapig-images-prod/app_araticum:base

# Clone app and npm install on server
ENV URL_TO_APPLICATION_GITHUB="https://github.com/lapig-ufg/restauracao-araticum.git"
ENV BRANCH="main"

LABEL maintainer="Renato Gomes <renatogomessilverio@gmail.com>"

RUN if [ -d "/APP/restauracao-araticum" ]; then rm -Rf /APP/restauracao-araticum; fi && \
cd /APP && git clone -b ${BRANCH} ${URL_TO_APPLICATION_GITHUB}

ADD ../../src/server/node_modules /APP/restauracao-araticum/src/server/node_modules
ADD ./src/client/dist/client /APP/restauracao-araticum/src/client/dist/client

CMD [ "/bin/bash", "-c", "/APP/src/server/prod-start.sh; tail -f /dev/null"]

ENTRYPOINT [ "/APP/Monitora.sh"]
9 changes: 5 additions & 4 deletions Dockerfile → docker/production/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
FROM registry.lapig.iesa.ufg.br/lapig-images-homol/app_araticum:base
FROM registry.lapig.iesa.ufg.br/lapig-images-homol/app_araticum:base

# Clone app and npm install on server
ENV URL_TO_APPLICATION_GITHUB="https://github.com/lapig-ufg/restauracao-araticum.git"
ENV BRANCH="develop"

LABEL maintainer="Renato Gomes <renatogomessilverio@gmail.com>"

RUN cd /APP && git clone -b ${BRANCH} ${URL_TO_APPLICATION_GITHUB} && \
cd /APP/restauracao-araticum/src/server && npm install && rm -rf /APP/plataform-base

RUN if [ -d "/APP/restauracao-araticum" ]; then rm -Rf /APP/restauracao-araticum; fi && \
cd /APP && git clone -b ${BRANCH} ${URL_TO_APPLICATION_GITHUB}

ADD ../../src/server/node_modules /APP/restauracao-araticum/src/server/node_modules
ADD ./src/client/dist/client /APP/restauracao-araticum/src/client/dist/client

CMD [ "/bin/bash", "-c", "/APP/src/server/prod-start.sh; tail -f /dev/null"]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions docs/docs/index.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added docs/imgs/logos/araticum_banner.jpeg
Binary file added docs/imgs/logos/favicon.ico
Binary file not shown.
Binary file added docs/imgs/logos/icone.png
Loading

0 comments on commit b132f46

Please sign in to comment.