Workflow file for this run
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 Deploy to EC2 | |
on: | |
push: | |
branches: [ "production", "main", "feat/173-docker-deploy" ] | |
pull_request: | |
branches: [ "production", "main" ] | |
jobs: | |
build-docker-image: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: make application.yml | |
run: | | |
mkdir -p ./src/main/resources | |
cd ./src/main/resources | |
touch ./application.yml | |
touch ./application-common.yml | |
touch ./application-prod.yml | |
echo "${{ secrets.APPLICATION }}" > ./application.yml | |
echo "${{ secrets.COMMON }}" > ./application-common.yml | |
echo "${{ secrets.PROD }}" > ./application-prod.yml | |
- name: make test application.yml | |
run: | | |
mkdir -p ./src/test/resources | |
cd ./src/test/resources | |
touch ./application.yml | |
touch ./application-test.yml | |
echo "${{ secrets.APPLICATION_TEST }}" > ./application.yml | |
echo "${{ secrets.TEST }}" > ./application-test.yml | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test | |
- name: docker login | |
uses: docker /login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: docker image build | |
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/gitget-application . | |
- name: dockerhub push | |
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/gitget-application | |
run-docker-image-on-ec2: | |
needs: build-docker-image | |
runs-on: self-hosted | |
steps: | |
- name: execute deploy.sh | |
run: sh /home/ec2-user/deploy.sh |