Skip to content

[WHD-122] Feat: portone payment api #96

[WHD-122] Feat: portone payment api

[WHD-122] Feat: portone payment api #96

Workflow file for this run

name: Deploy dev server
on:
push:
branches:
- "develop"
pull_request:
branches:
- "develop"
workflow_dispatch:
jobs:
run-test:
name: Run Test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Cache Gradle dependencies
uses: actions/cache@v3
with:
path: |
~/.gradle/caches/modules-2
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run tests
run: ./gradlew test --no-daemon
build:
name: Build And Push Docker Image
runs-on: ubuntu-latest
if: |
!contains(github.event.head_commit.message, 'skip deploy') &&
!contains(github.event.pull_request.body, 'skip deploy')
permissions:
contents: read
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Set commit SHA
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
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
run: |
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com
- name: Build and push Docker image for amd64
run: |
docker build --platform linux/amd64 \
-t ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:${{ env.COMMIT_SHA }}-amd64 .
docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:${{ env.COMMIT_SHA }}-amd64
- name: Create and push Docker manifest
run: |
docker manifest create ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:dev-${{ env.COMMIT_SHA }} \
--amend ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:${{ env.COMMIT_SHA }}-amd64
docker manifest push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:dev-${{ env.COMMIT_SHA }}
outputs:
commit_sha: ${{ env.COMMIT_SHA }}
deploy:
name: Deploy to EC2 dev server
runs-on: ubuntu-latest
needs: build
permissions:
contents: read
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Ssh to EC2 dev server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.AWS_DEV_EC2_HOST }}
username: ${{ secrets.AWS_DEV_EC2_USERNAME }}
key: ${{ secrets.AWS_DEV_EC2_PEM_KEY }}
port: 22
script: |
cd /home/ubuntu/workspace
echo "GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}" > .env
echo "GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}" >> .env
echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> .env
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> .env
echo "COMMIT_SHA=${{ needs.build.outputs.commit_sha }}" >> .env
echo "AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID }}" >> .env
echo "ECR_REPOSITORY=${{ secrets.ECR_REPOSITORY }}" >> .env
echo "PORTONE_REST_API_KEY=${{ secrets.PORTONE_REST_API_KEY }}" >> .env
echo "PORTONE_REST_API_SECRET=${{ secrets.PORTONE_REST_API_SECRET }}" >> .env
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{secrets.AWS_ACCOUNT_ID}}.dkr.ecr.ap-northeast-2.amazonaws.com
docker-compose down
docker images --format "{{.Repository}}:{{.Tag}} {{.ID}}" | grep "${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.ap-northeast-2.amazonaws.com/${{ secrets.ECR_REPOSITORY }}:dev-" | awk '{print $2}' | xargs docker rmi -f
docker-compose up -d