Skip to content

CD workflow test.

CD workflow test. #1

Workflow file for this run

name: CD - Deploy Backend
on:
workflow_dispatch:
push:
branches: [ "main" ]
paths:
- back-end/**
jobs:
deploy:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16.1
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: block_craft
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
defaults:
run:
working-directory: ./back-end
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
- name: Grant execute permissions to Maven Wrapper
run: chmod +x mvnw
- name: Login to Docker Hub
uses: docker/login-action@v3.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set build number
id: build-number
run: echo "BUILD_NUMBER=$(date '+%d.%m.%Y.%H.%M.%S')" >> $GITHUB_OUTPUT
- name: Build Package Push with Maven
run: mvn -ntp -B verify -Ddocker.image.tag=${{steps.build-number.outputs.BUILD_NUMBER}}
- name: Update Dockerrun.aws.json with new build number
run: |
echo "Dockerrun.aws.json before updating tag:"
cat Dockerrun.aws.json
sed -i -E 's_(170042060/blockcraft-api:)([^"]*)_\1'${{steps.build-number.outputs.BUILD_NUMBER}}'_' Dockerrun.aws.json
echo "Dockerrun.aws.json after updating tag:"
cat Dockerrun.aws.json
- name: Deploy to EB
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: back-end/Dockerrun.aws.json
- name: Commit and Push Dockerrun.aws.json
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "Update Dockerrun.aws.json docker image with new tag ${{ steps.build-number.outputs.BUILD_NUMBER }}"
git push