Merge remote-tracking branch 'origin/dataprev_producao' into dataprev… #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
push: | |
branches: | |
- dataprev_dsv | |
- dataprev_hmg | |
- dataprev_treina | |
- dataprev_producao | |
pull_request: | |
branches: | |
- dataprev_dsv | |
- dataprev_hmg | |
- dataprev_treina | |
- dataprev_producao | |
jobs: | |
build_producao: | |
name: Build on Producao | |
if: github.ref == 'refs/heads/dataprev_producao' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- name: Install dependencies | |
working-directory: ./front-end | |
run: npm install --legacy-peer-deps | |
- name: Install Angular CLI | |
run: npm install -g @angular/cli | |
- name: Build Angular and Run Postbuild | |
working-directory: ./front-end | |
run: | | |
ng build --configuration=production --output-path=../back-end/public | |
node ./postbuild.js | |
- name: Build Producao | |
env: | |
DOCKER_HUB_IMAGE: segescginf/pgdpetrvs | |
DOCKER_HUB_TAG_LATEST: latest | |
DOCKER_HUB_TAG_NEW: 2.3.6 | |
DOCKER_HUB_TAG_OLD: 2.3.5 | |
DOCKER_HUB_USERNAME: segescginf | |
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
DEPLOY_PATH: ./ | |
run: | | |
echo "Iniciando a construção e envio das imagens Docker..." | |
# Autentica no Docker Hub | |
echo $DOCKER_HUB_PASSWORD | docker login -u $DOCKER_HUB_USERNAME --password-stdin | |
# Função para verificar se uma tag existe no Docker Hub | |
tag_exists() { | |
curl --silent -f -lSL "https://hub.docker.com/v2/repositories/$DOCKER_HUB_IMAGE/tags/$1/" > /dev/null | |
} | |
# Puxa a imagem atual com a tag DOCKER_HUB_TAG_LATEST | |
docker pull $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG_LATEST | |
# Verifica se a tag $DOCKER_HUB_TAG_OLD já existe, e só reetiqueta se não existir | |
if tag_exists $DOCKER_HUB_TAG_OLD; then | |
echo "A tag $DOCKER_HUB_TAG_OLD já existe, não será reetiquetada." | |
else | |
docker tag $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG_LATEST $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG_OLD | |
docker push $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG_OLD | |
fi | |
# Constrói a nova imagem com a tag $DOCKER_HUB_TAG_NEW | |
docker build -t $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG_NEW -f ./resources/deploy/Dockerfile . | |
# Etiqueta a nova imagem como DOCKER_HUB_TAG_LATEST | |
docker tag $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG_NEW $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG_LATEST | |
# Envia as novas tags para o Docker Hub | |
docker push $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG_NEW | |
docker push $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG_LATEST | |
echo "Envio das imagens Docker concluído." | |
build_and_deploy_dsv: | |
name: Build and Deploy on Dataprev DSV | |
if: github.ref == 'refs/heads/dataprev_dsv' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- name: Install dependencies | |
working-directory: ./front-end | |
run: npm install --legacy-peer-deps | |
- name: Install Angular CLI | |
run: npm install -g @angular/cli | |
- name: Build Angular and Run Postbuild | |
working-directory: ./front-end | |
run: | | |
ng build --configuration=production --output-path=../back-end/public | |
node ./postbuild.js | |
- name: Build and Deploy DSV | |
env: | |
DOCKER_HUB_IMAGE: segescginf/pgdpetrvs-develop | |
DOCKER_HUB_TAG: dsv | |
SSH_USER: root | |
SSH_HOST: 200.152.38.137 | |
SSH_PORT: 7223 | |
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD_DSV }} | |
DEPLOY_PATH: ./ | |
DOCKER_HUB_USERNAME: segescginf | |
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
run: | | |
echo "Iniciando a construção e implantação do DSV..." | |
echo "Construindo a imagem Docker..." | |
docker build -t $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG -f ./resources/deploy/Dockerfile . | |
echo "Construção da imagem concluída. Enviando para o Docker Hub..." | |
echo $DOCKER_HUB_PASSWORD | docker login -u $DOCKER_HUB_USERNAME --password-stdin | |
docker push $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG | |
echo "Envio da imagem Docker concluído. Iniciando implantação no servidor remoto..." | |
sudo apt-get update -y && sudo apt-get install -y sshpass | |
sshpass -p $SSH_PASSWORD ssh -T -o StrictHostKeyChecking=no -p $SSH_PORT $SSH_USER@$SSH_HOST "cd /home/marcocoelho/ && bash install-pgd.sh < /dev/null" | |
echo "Implantação concluída com sucesso em DSV." | |
build_and_deploy_hmg: | |
name: Build and Deploy on Dataprev HMG | |
if: github.ref == 'refs/heads/dataprev_hmg' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- name: Install dependencies | |
working-directory: ./front-end | |
run: npm install --legacy-peer-deps | |
- name: Install Angular CLI | |
run: npm install -g @angular/cli | |
- name: Build Angular and Run Postbuild | |
working-directory: ./front-end | |
run: | | |
ng build --configuration=production --output-path=../back-end/public | |
node ./postbuild.js | |
- name: Build and Deploy HMG | |
env: | |
DOCKER_HUB_IMAGE: segescginf/pgdpetrvs-develop | |
DOCKER_HUB_TAG: hmg | |
SSH_USER: root | |
SSH_HOST: 200.152.38.137 | |
SSH_PORT: 7222 | |
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD_HMG }} | |
DEPLOY_PATH: ./ | |
DOCKER_HUB_USERNAME: segescginf | |
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
run: | | |
echo "Iniciando a construção e implantação do HMG..." | |
echo "Construindo a imagem Docker..." | |
docker build -t $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG -f ./resources/deploy/Dockerfile . | |
echo "Construção da imagem concluída. Enviando para o Docker Hub..." | |
docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD | |
docker push $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG | |
echo "Envio da imagem Docker concluído. Iniciando implantação no servidor remoto..." | |
sudo apt-get update -y && sudo apt-get install -y sshpass | |
# Executando o script install-pgd.sh | |
sshpass -p $SSH_PASSWORD ssh -T -o StrictHostKeyChecking=no -p $SSH_PORT $SSH_USER@$SSH_HOST "sh install-pgd.sh < /dev/null" | |
echo "Implantação concluída com sucesso em HMG." | |
build_and_deploy_treina: | |
name: Build and Deploy on Dataprev TREINA | |
if: github.ref == 'refs/heads/dataprev_treina' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- name: Install dependencies | |
working-directory: ./front-end | |
run: npm install --legacy-peer-deps | |
- name: Install Angular CLI | |
run: npm install -g @angular/cli | |
- name: Build Angular and Run Postbuild | |
working-directory: ./front-end | |
run: | | |
ng build --configuration=production --output-path=../back-end/public | |
node ./postbuild.js | |
- name: Build and Deploy TREINA | |
env: | |
DOCKER_HUB_IMAGE: segescginf/pgdpetrvs-develop | |
DOCKER_HUB_TAG: treina | |
SSH_USER: root | |
SSH_HOST: 200.152.38.137 | |
SSH_PORT: 7228 | |
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD_TREINA }} | |
DEPLOY_PATH: ./ | |
DOCKER_HUB_USERNAME: segescginf | |
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
run: | | |
echo "Iniciando a construção e implantação do TREINA..." | |
echo "Construindo a imagem Docker..." | |
docker build -t $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG -f ./resources/deploy/Dockerfile . | |
echo "Construção da imagem concluída. Enviando para o Docker Hub..." | |
docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD | |
docker push $DOCKER_HUB_IMAGE:$DOCKER_HUB_TAG | |
echo "Envio da imagem Docker concluído. Iniciando implantação no servidor remoto..." | |
sudo apt-get update -y && sudo apt-get install -y sshpass | |
# Executando o script install-pgd.sh | |
sshpass -p $SSH_PASSWORD ssh -T -o StrictHostKeyChecking=no -p $SSH_PORT $SSH_USER@$SSH_HOST "sh install-pgd.sh < /dev/null" | |
echo "Implantação concluída com sucesso em TREINA." |