Skip to content

official-gsm-prod-admin-server-ci #28

official-gsm-prod-admin-server-ci

official-gsm-prod-admin-server-ci #28

Workflow file for this run

name: official-gsm-prod-admin-server-ci
on:
push:
branches: [ "master" ]
workflow_dispatch:
jobs:
CI:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Set up JDK 17 job has success
if: ${{ success() }}
run: echo "set-up JDK 17 is succeeded"
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name : Setup Gradls's permission
run : chmod +x gradlew
- name : make yml file
run : mkdir ./src/main/resources
touch ./src/main/resources/application.yml
echo "${{ secrets.PROD_YML }}" > ./src/main/resources/application.yml
touch ./src/main/resources/application-oauth.yml
echo "${{ secrets.PROD_OAUTH_YML }}" > ./src/main/resources/application-oauth.yml
shell: bash
- name: Build with Gradle
run : ./gradlew clean build --exclude-task test
- 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: ap-northeast-2
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
touch scripts/prod-deploy.sh
echo "aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_REGISTRY" >> scripts/prod-deploy.sh
echo "docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/prod-deploy.sh
echo "docker image prune -f" >> scripts/prod-deploy.sh
echo "docker stop official-prod-admin-server" >> scripts/prod-deploy.sh
echo "docker rm official-prod-admin-server" >> scripts/prod-deploy.sh
echo "docker run -p 8080:8080 -d --restart always --name official-prod-admin-server --log-driver=awslogs --log-opt awslogs-region=ap-northeast-2 --log-opt awslogs-group=official-prod-log-group --log-opt awslogs-stream=admin-log $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/prod-deploy.sh
- name: upload to s3
env:
IMAGE_TAG: ${{ GITHUB.SHA }}
run: |
zip -r ${{ env.IMAGE_TAG }}.zip ./scripts appspec.yml
aws s3 cp --region ap-northeast-2 --acl private ./${{ env.IMAGE_TAG }}.zip s3://${{ secrets.PROD_BUCKET_NAME }}/admin/
- name: start deploy
env:
IMAGE_TAG: ${{ GITHUB.SHA }}
run: |
aws deploy create-deployment --application-name ${{ secrets.PROD_APP_NAME }} \
--deployment-config-name CodeDeployDefault.OneAtATime \
--deployment-group-name ${{ secrets.PROD_GROUP_NAME }} \
--s3-location bucket=${{ secrets.PROD_BUCKET_NAME }},bundleType=zip,key=admin/${{ env.IMAGE_TAG }}.zip
- name: official-gsm-prod-admin-server-ci-success
uses: sarisia/actions-status-discord@v1
if: ${{ success() }}
with:
title: official-gsm-prod-admin-server-ci-success
webhook: ${{ secrets.DISCORD_WEBHOOK }}
color: 00FF00
- name: official-gsm-prod-admin-server-ci-failed
uses: sarisia/actions-status-discord@v1
if: ${{ failure() }}
with:
title: official-gsm-prod-admin-server-ci-failed
webhook: ${{ secrets.DISCORD_WEBHOOK }}
color: FF0000