Skip to content

Commit

Permalink
adding cd build deploy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Rouchdane03 committed Nov 26, 2024
1 parent a417b9c commit e8634c8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
77 changes: 77 additions & 0 deletions .github/workflows/backend_guess_logic_number_cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: CD - build deploy guess_logic_number

on:
push:
branches:
- main
paths:
- '**'

jobs:
deploy:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:17.1
env:
POSTGRES_USER: rouchdane
POSTGRES_PASSWORD: password
POSTGRES_DB: game
ports:
- 5332:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
defaults:
run:
working-directory: .
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'

- name: Login to Docker Hub
uses: docker/login-action@v3.3.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set build number
id: build-number
run: echo "BUILD_NUMBER=$(date '+%d.%m.%Y.%H.%M.%S')" >> $GITHUB_OUTPUT

- name: run unit and integration test, Build app's docker image and replacing image tag with build_number value and Push to dockerhub
run: mvn -ntp -B verify -Ddocker.image.tag=${{steps.build-number.outputs.BUILD_NUMBER}} jib:build

- name: Update Dockerrun.aws.json with the newest application image tag which is build number
run: |
echo "Dockerrun.aws.json before updating tag"
cat Dockerrun.aws.json
sed -i -E 's_(rouchdane/guess_logic_number:)([^"]*)_\1'${{steps.build-number.outputs.BUILD_NUMBER}}'_' Dockerrun.aws.json
echo "Dockerrun.aws.json after updating tag"
cat Dockerrun.aws.json
- name: AWS Elastic Beanstalk Deploy the Updated Dockerrun.aws.json file
uses: einaregilsson/beanstalk-deploy@v22
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ secrets.AWS_EB_APPLICATION_NAME }}
environment_name: ${{ secrets.AWS_EB_ENVIRONMENT_NAME }}
version_label: ${{steps.build-number.outputs.BUILD_NUMBER}}
version_description: ${{github.SHA}}
region: ${{ secrets.AWS_EB_REGION }}
deployment_package: Dockerrun.aws.json

- name: Commit and push Dockerrun.aws.json to our github repo
run: |
git config user.name github actions
git config user.email github actions@github.com
git add .
git commit -m "Update Dockerrun.aws.json specifically our docker app image with new tag ${{steps.build-number.outputs.BUILD_NUMBER}}"
git push
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
</platforms>
</from>
<to>
<image>docker.io/${docker.username}/${docker.image.name}:${project.version}</image>
<image>docker.io/${docker.username}/${docker.image.name}:${docker.image.tag}</image>
<tags>
<tag>latest</tag>
</tags>
Expand Down

0 comments on commit e8634c8

Please sign in to comment.