Skip to content

build-deploy-api

build-deploy-api #1

name: build-deploy-api
on:
workflow_dispatch:
branches:
- master
push:
paths:
- "src/**"
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "adopt"
- name: Make envfile
uses: SpicyPizza/create-envfile@v1.3
with:
envKey_DATABASE_SOURCE: ${{ vars.DATABASE_SOURCE}}
directory: ./src/main/resources
file_name: .env
fail_on_empty: true
- name: build java spring
working-directory: ./
run: |
./gradlew clean
./gradlew build --exclude-task test
shell: bash
- name: package as docker image
working-directory: ./
run: |
docker build -t api ./
docker save -o api.tar api
- name: package as code deploy zip
working-directory: ./
run: |
cp .deploy/appspec/api.yml ./appspec.yml
cp .deploy/script/docker-restart.sh ./script.sh
zip -r ./deploy-api.zip api.tar appspec.yml script.sh
- 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: ${{ vars.AWS_REGION }}
- name: Upload to S3
working-directory: ./
run: |
aws s3 cp --region ${{ vars.AWS_REGION }} ./deploy-api.zip s3://${{ vars.DEPLOY_S3_BUCKET }}/deploy-api.zip
- name: Code Deploy
run: |
aws deploy create-deployment \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--application-name ${{ vars.CODE_DEPLOY_APPLICATION_NAME }} \
--deployment-group-name ${{ vars.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=${{ vars.DEPLOY_S3_BUCKET }},bundleType=zip,key=deploy-api.zip