Merge branch 'main' into backend-ci-cd #32
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: Deploy to EC2 | |
on: | |
push: | |
branches: | |
- backend-ci-cd | |
jobs: | |
build_and_push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Maven | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'adopt' | |
java-version: '17' | |
- name: Create .env file | |
run: | | |
cd app/backend/src/main/resources | |
echo "${{ secrets.ENVIRONMENT_VARIABLES }}" > .env | |
- name: Build with Maven | |
run: | | |
cd app/backend | |
mvn clean install | |
- name: Build Docker image | |
run: | | |
cd app/backend | |
docker build -t bounswe2023group5:latest . | |
- name: Login to Docker Hub | |
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
- name: Push to Docker Hub | |
run: | | |
docker tag bounswe2023group5:latest unaldenizzz/bounswe2023group5:latest | |
docker push unaldenizzz/bounswe2023group5:latest | |
deploy_to_ec2: | |
needs: build_and_push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to EC2 | |
env: | |
PRIVATE_KEY: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | |
run: | | |
echo "$PRIVATE_KEY" > private_key.pem | |
chmod 600 private_key.pem | |
ssh -o StrictHostKeyChecking=no -i private_key.pem [email protected] 'bash /home/ubuntu/scripts/updateswe' |