test-migrate-deploy #15
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | |
name: test-migrate-deploy | |
on: | |
workflow_dispatch: | |
env: | |
DOCKER_USER: ${{ secrets.DOCKER_USER }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
IMAGE_NAME: wken5577/test-migrate-server | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
- name: Make application ymls | |
run: | | |
cd ./src/main/resources | |
echo "${{ secrets.MIGRATE_APPLICATION_YML }}" | base64 -d > application.yml | |
shell: bash | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ env.DOCKER_USER }} | |
password: ${{ env.DOCKER_PASSWORD }} | |
- name: Build with Gradle | |
run: ./gradlew clean build | |
- name: build new docker image as latest tag | |
run: | | |
docker build -t ${{ env.IMAGE_NAME }}:latest . | |
docker push ${{ env.IMAGE_NAME }}:latest | |
- name: Get Github Actions IP | |
id: ip | |
uses: haythem/public-ip@v1.3 | |
- name: AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_TEST_MIGRATE_SECURITY_SECRET_KEY }} | |
aws-region: ap-northeast-2 | |
- name: Add Github Actions IP to Security group | |
run: | | |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_TEST_MIGRATE_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | |
- name: executing docker-compose up on test server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.TEST_MIGRATE_SERVER_HOST }} | |
username: ${{ secrets.TEST_MIGRATE_SERVER_USERNAME }} | |
key: ${{ secrets.TEST_MIGRATE_SERVER_PEM }} | |
script: | | |
cd ./docker | |
docker stop tomcat | |
docker rm tomcat | |
docker rmi ${{ env.IMAGE_NAME }}:latest | |
docker-compose up -d | |
- name: Remove Github Actions IP From Security Group | |
run: | | |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_TEST_MIGRATE_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 |