Merge pull request #5 from LearnMate-Dev/feature/3-implements-deploy-… #1
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: Build and Push Docker Image with Jib | |
on: | |
push: | |
branches: ["main"] | |
permissions: | |
contents: read | |
jobs: | |
build-and-push-image: | |
runs-on: self-hosted | |
steps: | |
- name: Checkout Repository and Submodules | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
token: ${{ secrets.ACTIONS_TOKEN }} | |
- name: Copy application.yml from submodule | |
run: | | |
mkdir -p src/main/resources | |
cp application-config/application-prod.yml src/main/resources/application-prod.yml | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: "21" | |
distribution: "temurin" | |
- name: Build and push Docker image | |
run: | | |
./gradlew jib -x test \ | |
-Djib.to.tags=${{ github.sha }} \ | |
-Djib.to.auth.username=${{ secrets.DOCKER_USERNAME }} \ | |
-Djib.to.auth.password=${{ secrets.DOCKER_PASSWORD }} | |
- name: Push Docker image to EC2 server | |
env: | |
DOCKER_IMAGE: "${{ secrets.DOCKER_USERNAME }}/learnMate:${{ github.sha }}" | |
run: | | |
ssh -o "StrictHostKeyChecking=no" -i ${{ secrets.EC2_SSH_KEY }} ec2-user@${{ secrets.EC2_HOST }} "docker pull $DOCKER_IMAGE && docker run -d -p 8080:8080 $DOCKER_IMAGE" |