-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9783992
commit 2846574
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Build Image and Push to ECR | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
- 'develop' | ||
|
||
env: | ||
ECR_ROOT: ${{ secrets.AWS_ECR_ROOT_2 }} | ||
ECR_REPOSITORY: lgtm-api-server | ||
IMAGE_NAME: lgtm-api-server:${{ github.ref_name }}_0.0.${{ github.run_number }} | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
working-directory: ./API-Server | ||
|
||
steps: | ||
- name: echo initial env values | ||
run: | | ||
echo $ECR_ROOT | ||
echo $ECR_REPOSITORY | ||
echo $IMAGE_NAME | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Java | ||
uses: actions/setup-java@v2 | ||
with: | ||
java-version: '17' | ||
distribution: 'adopt' | ||
|
||
- name: Start Redis | ||
uses: supercharge/redis-github-action@1.6.0 | ||
with: | ||
redis-version: '7' | ||
|
||
- name: Build and test Spring Boot project | ||
run: | | ||
touch ./src/main/resources/application-test.yml | ||
echo "${{ secrets.APPLICATION_TEST_YML }}" > ./src/main/resources/application-test.yml | ||
cat ./src/main/resources/application-test.yml | ||
chmod +x ./gradlew | ||
mkdir -p ./src/main/resources/static/docs | ||
./gradlew build --no-daemon | ||
working-directory: ${{ env.working-directory }} | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_2 }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_2 }} | ||
aws-region: ap-northeast-2 | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
id: build-image | ||
run: | | ||
# docker build | ||
docker build -t $IMAGE_NAME . | ||
# upload img(:branch&version) to ECR | ||
docker tag $IMAGE_NAME $ECR_ROOT/$IMAGE_NAME | ||
docker push $ECR_ROOT/$IMAGE_NAME | ||
# upload img(:latest) to ECR | ||
docker tag $IMAGE_NAME $ECR_ROOT/$ECR_REPOSITORY:latest | ||
docker push $ECR_ROOT/$ECR_REPOSITORY:latest | ||
working-directory: ${{ env.working-directory }} |