Merge pull request #30 from hellokitty-coding-club/feature/#2-signup-… #39
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
name: Build Image and Push to ECR | |
on: | |
push: | |
branches: | |
- 'main' | |
- 'develop' | |
env: | |
ECR_ROOT: ${{ secrets.AWS_ECR_ROOT }} | |
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: 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 }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
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 }} |