Skip to content

Commit

Permalink
Create buildImage2.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
great-park authored Nov 9, 2023
1 parent 9783992 commit 2846574
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/buildImage2.yml
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 }}

0 comments on commit 2846574

Please sign in to comment.