Skip to content

Merge pull request #141 from hellokitty-coding-club/feature/#139-miss… #9

Merge pull request #141 from hellokitty-coding-club/feature/#139-miss…

Merge pull request #141 from hellokitty-coding-club/feature/#139-miss… #9

Workflow file for this run

name: Build Image and Push to ECR in account_v2
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 }}