-
Notifications
You must be signed in to change notification settings - Fork 3
75 lines (62 loc) · 2.12 KB
/
buildImage2.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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 }}