Skip to content

Commit

Permalink
Merge pull request #4 from lapig-ufg/email
Browse files Browse the repository at this point in the history
worker
  • Loading branch information
jairomr authored Oct 1, 2024
2 parents 40eca15 + 95111fc commit 7bd48c4
Showing 1 changed file with 20 additions and 95 deletions.
115 changes: 20 additions & 95 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,98 +94,23 @@ jobs:
id: delete_container
continue-on-error: true
run: |
delete_status_api=$(curl -v -X DELETE -w "%{http_code}" http://$DOCKER_HOST/containers/task_api?force=true 2>/dev/null)
delete_status_dash=$(curl -v -X DELETE -w "%{http_code}" http://$DOCKER_HOST/containers/task_dashboard?force=true 2>/dev/null)
delete_status_redis=$(curl -v -X DELETE -w "%{http_code}" http://$DOCKER_HOST/containers/task_redis?force=true 2>/dev/null)
delete_status_work=$(curl -v -X DELETE -w "%{http_code}" http://$DOCKER_HOST/containers/task_worker?force=true 2>/dev/null)
echo $delete_status_api
- name: Deploy Container
id: deploy_container
run: |
create_status_api=$(curl -v -X POST -H 'Content-Type: application/json' -d @/compose/$application_name/api.json -s -o /dev/null -w "%{http_code}" http://$DOCKER_HOST/containers/create?name=task_api 2>/dev/null)
create_status_dash=$(curl -v -X POST -H 'Content-Type: application/json' -d @/compose/$application_name/dashboard.json -s -o /dev/null -w "%{http_code}" http://$DOCKER_HOST/containers/create?name=task_dashboard 2>/dev/null)
create_status_redis=$(curl -v -X POST -H 'Content-Type: application/json' -d @/compose/$application_name/redis.json -s -o /dev/null -w "%{http_code}" http://$DOCKER_HOST/containers/create?name=task_redis 2>/dev/null)
create_status_work=$(curl -v -X POST -H 'Content-Type: application/json' -d @/compose/$application_name/worker.json -s -o /dev/null -w "%{http_code}" http://$DOCKER_HOST/containers/create?name=task_worker 2>/dev/null)
echo $create_status_api
- name: Start Container
id: start_container
run: |
start_status_redis=$(curl -v -X POST -s -o /dev/null -w "%{http_code}" http://$DOCKER_HOST/containers/task_redis/start 2>/dev/null)
start_status_api=$(curl -v -X POST -s -o /dev/null -w "%{http_code}" http://$DOCKER_HOST/containers/task_api/start 2>/dev/null)
start_status_dash=$(curl -v -X POST -s -o /dev/null -w "%{http_code}" http://$DOCKER_HOST/containers/task_dashboard/start 2>/dev/null)
start_status_work=$(curl -v -X POST -s -o /dev/null -w "%{http_code}" http://$DOCKER_HOST/containers/task_worker/start 2>/dev/null)
echo $start_status_api
post-deploy:
runs-on: ubuntu-latest
needs: deploy
if: ${{ always() || needs.build.result == 'failure' ||needs.deploy.result == 'failure' }}
steps:
- name: Load env
run: |
echo "LAST_COMMIT_HASH=${{needs.build.outputs.LAST_COMMIT_HASH}}" >> $GITHUB_ENV
echo "LAPIG_AUTHOR_NAME=${{needs.build.outputs.LAPIG_AUTHOR_NAME}}" >> $GITHUB_ENV
echo "LAPIG_AUTHOR_EMAIL=${{needs.build.outputs.LAPIG_AUTHOR_EMAIL}}" >> $GITHUB_ENV
echo "LAPIG_AUTHOR_DATE=${{needs.build.outputs.LAPIG_AUTHOR_DATE}}" >> $GITHUB_ENV
echo "LAPIG_PROJECT_NAME=${{needs.build.outputs.LAPIG_PROJECT_NAME}}" >> $GITHUB_ENV
echo "LAPIG_COMMIT_DATE=${{needs.build.outputs.LAPIG_COMMIT_DATE}}" >> $GITHUB_ENV
echo "CREATE_STATUS=${{needs.deploy.outputs.CREATE_STATUS}}" >> $GITHUB_ENV
echo "DELETE_STATUS=${{needs.deploy.outputs.DELETE_STATUS}}" >> $GITHUB_ENV
echo "START_STATUS=${{needs.deploy.outputs.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${{ secrets.TELEGRAM_API_KEY }}/sendMessage" -d "chat_id=${{ secrets.CHAT_ID }}" -d "parse_mode=markdown" -d "text=*Project*: *${LAPIG_PROJECT_NAME}*\
*Status:*${{ needs.deploy.result }}\
*Branch*: ${LAPIG_BRANCH_NAME}\
*Author*: *${LAPIG_AUTHOR_NAME}*\
*Author_Email*: *${LAPIG_AUTHOR_EMAIL}*\
*Commit_ID*: *${LAST_COMMIT_HASH}*\
*Date_Commit*: *${LAPIG_COMMIT_DATE}*\
*Duration*: *${LAPIG_DURATION}*"
- name: creat message to Discord
run: |
if [[ "${{ needs.deploy.result }}" == "success" && "$START_STATUS" == "OK" && "$DELETE_STATUS" == "OK" && "$CREATE_STATUS" == "OK" ]]; then
echo "avatar_url=${{vars.LAPIG_SUCCESS}}" >> $GITHUB_ENV
status_geral="Sucesso"
else
echo "avatar_url=${{vars.LAPIG_ERROR}}" >> $GITHUB_ENV
status_geral="Falhou"
fi
case $START_STATUS in
"OK") START_STATUS_D="{ \"title\": \"DOCKER START OK!\",\"color\": 65280},";;
*) START_STATUS_D="{ \"title\": \"DOCKER START ERROR!\",\"color\": 16711680},";;
esac
case $DELETE_STATUS in
"OK") DELETE_STATUS_D="{ \"title\": \"DOCKER DELETE OK!\",\"color\": 65280},";;
*) DELETE_STATUS_D="{ \"title\": \"DOCKER DELETE ERROR!\",\"color\": 16711680},";;
esac
case $CREATE_STATUS in
"OK") CREATE_STATUS_D="{ \"title\": \"DOCKER CREATE OK!\",\"color\": 65280},";;
*) CREATE_STATUS_D="{ \"title\": \"DOCKER CREATE ERROR!\",\"color\": 16711680},";;
esac
echo "EMBEDS_STATUS=$DELETE_STATUS_D $CREATE_STATUS_D $START_STATUS_D" >> $GITHUB_ENV
echo "discordDesc=Result: $status_geral\nProject: $LAPIG_PROJECT_NAME\nCommit: $LAST_COMMIT_HASH\nAuthor: $LAPIG_AUTHOR_NAME\nAuthor_Email: $LAPIG_AUTHOR_EMAIL\nDate: $LAPIG_COMMIT_DATE\nDuration: $LAPIG_DURATION seconds" >> $GITHUB_ENV
echo "discordFooter=${{ github.workflow }} (#${{ github.run_number }})" >> $GITHUB_ENV
echo "discordTitle=${{ github.workflow }} (build #${{ github.run_number }})" >> $GITHUB_ENV
- name: Send menssage to Discord
run: |
echo "{\"content\": \"$discordTitle\", \"embeds\": [ { \"title\": \"$discordTitle\", \"description\": \"$discordDesc\", \"footer\": { \"text\": \"$discordFooter\" }, \"thumbnail\": { \"url\":\"$avatar_url\"} }, $EMBEDS_STATUS] ], \"username\": \"GitHub Actions\", \"avatar_url\": \"$avatar_url\" }"
curl -H "Content-Type: application/json" -X POST -d "{\"content\": \"$discordTitle\", \"embeds\": [ $EMBEDS_STATUS { \"title\": \"$discordTitle\", \"description\": \"$discordDesc\", \"footer\": { \"text\": \"$discordFooter\" }, \"thumbnail\": { \"url\":\"$avatar_url\"} }], \"username\": \"GitHub Actions\", \"avatar_url\": \"$avatar_url\" }" https://discord.com/api/webhooks/${{ secrets.DISCORD_KEY }}
/compose/resetapp.sh --title "Task api" \
--container "task_api" \
--github "https://github.com/${{ github.repository }}" \
--commit "${{ needs.build.outputs.LAST_COMMIT_HASH }}" \
${{ needs.build.outputs.APPLICATION_NAME }}
/compose/resetapp.sh --title "Task Dashboard" \
--container "task_dashboard" \
--github "https://github.com/${{ github.repository }}" \
--commit "${{ needs.build.outputs.LAST_COMMIT_HASH }}" \
${{ needs.build.outputs.APPLICATION_NAME }}
/compose/resetapp.sh --title "Task Redis" \
--container "task_redis" \
--github "https://github.com/${{ github.repository }}" \
--commit "${{ needs.build.outputs.LAST_COMMIT_HASH }}" \
${{ needs.build.outputs.APPLICATION_NAME }}
/compose/resetapp.sh --title "Task Worker" \
--container "task_worker" \
--github "https://github.com/${{ github.repository }}" \
--commit "${{ needs.build.outputs.LAST_COMMIT_HASH }}" \
${{ needs.build.outputs.APPLICATION_NAME }}

0 comments on commit 7bd48c4

Please sign in to comment.