Skip to content

Update ci.cd.prod.yml #5

Update ci.cd.prod.yml

Update ci.cd.prod.yml #5

Workflow file for this run

name: Java CI with Gradle
on:
push:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: make application-key.properties
run: |
cd ./src/main/resources
touch ./application-key.properties
echo "${{ secrets.APPLICATION_KEY }}" > ./application-key.properties
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build with Gradle
#uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
#with:
#arguments: build
run : ./gradlew clean build --exclude-task test
- name: Copy script to EC2 instance
run: |
scp -i $HOME/key.pem -o StrictHostKeyChecking=no path/to/local/script.sh ${SSH_USER}@${SSH_KNOWN_HOSTS}:/home/${SSH_USER}/
- name: Build and deploy
run: |
echo "$SSH_PEM_KEY" > $HOME/key.pem
chmod 600 $HOME/key.pem
ssh -i $HOME/key.pem -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_KNOWN_HOSTS} '~/script.sh'
env:
SSH_USER: ${{secrets.EC2_USER}}
SSH_KNOWN_HOSTS: ${{secrets.EC2_HOST}}
SSH_PEM_KEY: ${{secrets.EC2_KEY}}