♻️ 열차마다 혼잡도 가져오도록 수정 (#198) (#199) #189
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 | |
on: | |
push: | |
branches: | |
- develop | |
env: | |
ECR_REGISTRY: ${{ secrets.AWS_ECR_REGISTRY }} | |
ECR_REPOSITORY: ahachul | |
AWS_REGION: ap-northeast-2 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.TOKEN_GITHUB }} | |
submodules: true | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 17 | |
- name: Grant execute permission for gradlew | |
run: chmod +x ahachul_backend/gradlew | |
shell: bash | |
- name: Build with Gradle | |
run: cd ./ahachul_backend && SPRING_PROFILES_ACTIVE=test ./gradlew clean copyDocument jar build | |
shell: bash | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Build, tag, and push image to Amazon ECR | |
id: build-image | |
run: | | |
docker build -t ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest . | |
docker push ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest | |
echo "success push to ecr: name=image::${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest" | |
deploy: | |
needs: build | |
runs-on: self-hosted | |
steps: | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Pull Image and docker run | |
run: | | |
docker pull ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest | |
docker stop ${{ env.ECR_REPOSITORY }} && docker rm ${{ env.ECR_REPOSITORY }} && docker rmi ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest | |
docker run -v /home/ec2-user/ahachul_data/datas/:/home -d -p 8080:8080 --name ${{ env.ECR_REPOSITORY }} --restart always ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest | |
clean: | |
needs: deploy | |
runs-on: self-hosted | |
steps: | |
- name: Remove inactive images | |
run: | | |
sudo docker images | grep "<none>" | awk "{print \$3}" | xargs -r sudo docker rmi |