-
Notifications
You must be signed in to change notification settings - Fork 15
108 lines (94 loc) · 3.92 KB
/
back-ci.yaml
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: CI/CD
on:
push:
paths:
- "backend/**"
workflow_dispatch:
jobs:
backend-CI:
runs-on: ubuntu-latest
steps:
- name: 체크아웃
uses: actions/checkout@v3
- name: JDK 11 설정
uses: actions/setup-java@v3
with:
java-version: "11"
distribution: "corretto"
- name: Setup Dev Environment
if: ${{ 'refs/heads/dev' == github.ref }}
run: |
echo "ENVIRONMENT=dev" >> $GITHUB_ENV
echo "S3_BUCKET=dev.cabi-server-deploy" >> $GITHUB_ENV
echo "CODEDEPLOY_APP=cabi-dev" >> $GITHUB_ENV
echo "CODEDEPLOY_GROUP=cabi-dev-group" >> $GITHUB_ENV
echo "DOCKER_IMAGE=ccabi/cabi-dev" >> $GITHUB_ENV
- name: Setup Main Environment
if: ${{ 'refs/heads/main' == github.ref }}
run: |
echo "ENVIRONMENT=main" >> $GITHUB_ENV
echo "S3_BUCKET=main.cabi-server-deploy" >> $GITHUB_ENV
echo "CODEDEPLOY_APP=cabi-main" >> $GITHUB_ENV
echo "CODEDEPLOY_GROUP=cabi-main-group" >> $GITHUB_ENV
echo "DOCKER_IMAGE=ccabi/cabi-main" >> $GITHUB_ENV
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Gradle 빌드
run: |
cd backend
mkdir -p build/generated-snippets/
chmod +x gradlew
./gradlew build -x test
shell: bash
- name: Log in to Docker Hub
if: ${{ format('refs/heads/{0}', env.ENVIRONMENT) == github.ref }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
if: ${{ format('refs/heads/{0}', env.ENVIRONMENT) == github.ref }}
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE }}
tags: latest
- name: Build and push Docker image
if: ${{ format('refs/heads/{0}', env.ENVIRONMENT) == github.ref }}
uses: docker/build-push-action@v5
with:
context: .
file: ./deploy-${{ env.ENVIRONMENT }}/pinpoint-application/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Configure AWS credentials
if: ${{ format('refs/heads/{0}', env.ENVIRONMENT) == github.ref }}
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: ${{ secrets.AWS_REGION }}
- name: Upload to S3 and deploy
if: ${{ format('refs/heads/{0}', env.ENVIRONMENT) == github.ref }}
run: |
env_file="deploy-${{ env.ENVIRONMENT }}/pinpoint-application/.env"
agent_env_file="deploy-${{ env.ENVIRONMENT }}/pinpoint-agent/.env"
echo "${{ secrets[format('PINPOINT_APPLICATION_{0}_ENV', env.ENVIRONMENT)] }}" | base64 --decode > $env_file
echo "${{ secrets[format('PINPOINT_AGENT_{0}_ENV', env.ENVIRONMENT)] }}" | base64 --decode > $agent_env_file
mkdir -p deploy && cp -r deploy-${{ env.ENVIRONMENT }}/* deploy/
zip -r deploy.zip deploy
aws s3 cp deploy.zip s3://${{ env.S3_BUCKET }}/deploy.zip
aws deploy create-deployment \
--application-name ${{ ENV.CODEDEPLOY_APP }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ ENV.CODEDEPLOY_GROUP }} \
--file-exists-behavior OVERWRITE \
--s3-location bucket=${{ env.S3_BUCKET }},bundleType=zip,key=deploy.zip