Skip to content

Fix: branch main to master #107

Fix: branch main to master

Fix: branch main to master #107

Workflow file for this run

name: spurt CICD
on:
push:
branches:
- master
jobs:
push_to_registry:
name: Push to aws container registry
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- name: make application.yml
if: contains(github.ref, 'master')
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.YML_PROD }}" > ./application.yml
shell: bash
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build -x spotlessJavaCheck
cache-read-only: ${{ github.ref != 'refs/heads/master' }}
- name: save docs file
uses: actions/upload-artifact@v3
with:
name: api-docs
path: build/docs/asciidoc
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker build & push to prod
if: contains(github.ref, 'master')
run: |
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t spurt-be -f Dockerfile .
docker tag spurt-be:latest ${{ secrets.DOCKER_USER }}/spurt-be:latest
docker push ${{ secrets.DOCKER_USER }}/spurt-be:latest
pull_from_registry:
name: Connect server ssh and pull from container registry
needs: push_to_registry
runs-on: ubuntu-latest
steps:
- name: Deploy to prod
if: contains(github.ref, 'master')
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_NAME }}
username: ${{ secrets.AWS_USER_NAME }}
key: ${{ secrets.AWS_PRIVATE_KEY }}
port: ${{ secrets.AWS_PORT }}
script: |
docker pull ${{ secrets.DOCKER_USER }}/spurt-be:latest
docker stop spurt-be
docker rm spurt-be
docker run -d --network spurt --name spurt-be -p 8080:8080 ${{ secrets.DOCKER_USER }}/spurt-be
if docker images -f "dangling=true" -q | grep . > /dev/null; then
docker rmi $(docker images -f "dangling=true" -q)
fi
upload_docs:
name: upload api docs
needs: push_to_registry
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
AWS_REGION: ap-northeast-2
steps:
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: api-docs
- name: Upload binary to S3 bucket
uses: jakejarvis/s3-sync-action@master
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_NAME }}
SOURCE_DIR: .
- name: Invalidate cache CloudFront
uses: chetan/invalidate-cloudfront-action@master
env:
DISTRIBUTION: ${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}
PATHS: '/*'
continue-on-error: true