Frontend pipeline #20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pipeline Backend | |
on: | |
push: | |
paths: | |
- book-sweeper/** | |
- docker/backend/Dockerfile | |
- 'docker-compose.yml' | |
- .github/workflows/*-backend.yml | |
jobs: | |
compile: | |
runs-on: ubuntu-latest | |
name: Compile project | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: 'corretto' | |
- name: Compile | |
run: | | |
cd book-sweeper | |
./mvnw clean compile | |
unit-tests: | |
runs-on: ubuntu-latest | |
name: Unit tests | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: 'corretto' | |
- name: Unit Tests | |
run: | | |
cd book-sweeper | |
./mvnw clean test | |
build: | |
runs-on: ubuntu-latest | |
needs: [compile, unit-tests] | |
name: Build project | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: 'corretto' | |
- name: Build project | |
run: | | |
cd book-sweeper | |
./mvnw clean package | |
build-image: | |
runs-on: ubuntu-latest | |
needs: [build] | |
name: Build Docker image | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: 'corretto' | |
- name: Extract version | |
id: extract_version | |
run: | | |
cd book-sweeper | |
echo "VERSION=$(./mvnw -q -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_OUTPUT | |
- name: Login to Dockerhub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: book-sweeper | |
file: docker/backend/Dockerfile | |
push: true | |
platforms: linux/amd64 | |
tags: ${{ secrets.DOCKER_USERNAME }}/book-sweeper-backend:${{ steps.extract_version.outputs.VERSION }} | |
build-args: | | |
PROFILE=dev | |
APP_VERSION=${{ steps.extract_version.outputs.VERSION }} | |
deploy: | |
needs: [build-image] | |
runs-on: ubuntu-latest | |
name: Deploy to AWS EC2 | |
steps: | |
- name: AWS SSM Send-Command | |
uses: peterkimzz/aws-ssm-send-command@v1.1.1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
instance-ids: ${{ secrets.AWS_INSTANCE_ID }} | |
working-directory: /home/ec2-user | |
command: | | |
sudo docker-compose stop | |
sudo docker-compose rm -f | |
sudo docker-compose pull | |
sudo docker-compose up -d | |
sudo docker image prune -af |