diff --git a/.github/workflows/backend_guess_logic_number_cd.yml b/.github/workflows/backend_guess_logic_number_cd.yml index e69de29..04074da 100644 --- a/.github/workflows/backend_guess_logic_number_cd.yml +++ b/.github/workflows/backend_guess_logic_number_cd.yml @@ -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 diff --git a/pom.xml b/pom.xml index 953f5bf..31fc3c1 100644 --- a/pom.xml +++ b/pom.xml @@ -176,7 +176,7 @@ - docker.io/${docker.username}/${docker.image.name}:${project.version} + docker.io/${docker.username}/${docker.image.name}:${docker.image.tag} latest