-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (110 loc) · 4.48 KB
/
backend-cd.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
110
111
112
name: CD - Deploy Backend
on:
workflow_dispatch:
push:
branches:
- master
paths:
- backend/**
jobs:
deploy:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15.5
env:
POSTGRES_USER: ahmed
POSTGRES_PASSWORD: password
POSTGRES_DB: customer
ports:
- 5332:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
defaults:
run:
working-directory: ./backend
steps:
- name: Send custom JSON data to Slack workflow
id: slack
uses: slackapi/[email protected]
with:
# For posting a rich message using Block Kit
payload: |
{
"text": "GitHub Action build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "GitHub Action build result: ${{ job.status }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_ACCESS_TOKEN}}
- name: Slack - Docker Hub login
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"Connected to Docker"}' ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Set build number
id: build-number
run: echo "BUILD_NUMBER=$(date '+%d.%m.%Y.%H.%M.%S')" >> $GITHUB_OUTPUT
- name: Slack - Maven build
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"Building with Maven :maven:"}' ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Build Package Push with Maven
run: mvn -ntp -B verify -Ddocker.image.tag=${{steps.build-number.outputs.BUILD_NUMBER}} jib:build
- name: Slack - Dockerrun.aws.json changes
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"Update Dockerrun.aws.json"}' ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Update Dockerrun.aws.json api image tag with new Build Number
run: |
echo "Dockerrun.aws.json before updating tag"
cat Dockerrun.aws.json
sed -i -E 's_(hematophobia/asxms-api:)([^"]*)_\1'${{steps.build-number.outputs.BUILD_NUMBER}}'_' Dockerrun.aws.json
echo "Dockerrun.aws.json after updating tag"
cat Dockerrun.aws.json
- name: Slack - AWS Beanstalk deploy
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"Deploy in :aws:"}' ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Deploy to Elastic Beanstalk
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ secrets.EB_APPLICATION_NAME }}
environment_name: ${{ secrets.EB_ENVIRONMENT_NAME }}
version_label: ${{ steps.build-number.outputs.BUILD_NUMBER }}
version_description: ${{ github.SHA }}
region: ${{ secrets.EB_REGION }}
deployment_package: backend/Dockerrun.aws.json
- name: Slack - Commit
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"Commit new version of the project :github_check_mark:"}' ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Commit and Push Dockerrun.aws.json
run: |
git config user.name github-actions
git config user.email [email protected]
git add .
git commit -m "Update Dockerrun.aws.json docker image with new tag ${{ steps.build-number.outputs.BUILD_NUMBER }}"
git push
- name: Slack - End
if: always()
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":"Job status ${{ job.status }}"}' ${{ secrets.SLACK_WEBHOOK_URL }}