Github action을 이용해서 S3에 빌드한 jar 파일을 업로드할 수 있도록 설정해 보자.
github action을 새로 생성해 보자
.github/workflow/develop.yml
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle
name: Springbootcamp Dev Release
on:
push:
branches:
- develop
pull_request:
branches:
- develop
workflow_dispatch:
env:
S3_BUCKET_NAME: springbootcamp
AWS_REGION: ap-northeast-2 # set this to your preferred AWS region, e.g. us-west-1
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
environment: develop # production
steps:
- name: checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: Build with Gradle
run: ./gradlew clean bootJar
shell: bash
- name: Prepare jar
run: cp ./build/libs/*.jar ./springbootcamp.jar
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: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./springbootcamp.jar s3://$S3_BUCKET_NAME/springbootcamp.jar
먼저 사용할 환경을 생성 해야 한다.
settings > environment > develop
생성하고,
develop 환경에 IAM user의 access key를 추가해 준다.
이제 push가 발생했을때 다음과 같이 pipleline이 동작하는 것을 볼 수 있다.
이제 S3에 업로드된 파일을 확인해 보자.