-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildspec.yml
More file actions
68 lines (63 loc) · 3.2 KB
/
buildspec.yml
File metadata and controls
68 lines (63 loc) · 3.2 KB
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
version: 0.2
phases:
install:
commands:
- echo Installing Helm...
- curl -sSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
- echo Installing yq...
- curl -L https://github.com/mikefarah/yq/releases/download/v4.9.8/yq_linux_amd64 -o /usr/bin/yq
- chmod +x /usr/bin/yq
pre_build:
commands:
- echo Starting Docker daemon...
- nohup /usr/local/bin/dockerd > /dev/null 2>&1 &
- timeout 15 sh -c "until docker info; do echo 'Waiting for Docker to start...'; sleep 1; done"
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_URL
- chmod +x ./gradlew
- echo Configuring Git for GitHub...
- git config --global credential.helper store
- echo "${GITHUB_USERNAME}:${GITHUB_TOKEN}" > ~/.git-credentials
- echo Cloning HelmChart repository from GitHub...
- git clone https://${GITHUB_USERNAME}:${GITHUB_TOKEN}@github.com/SK-Rookies-Final3/HelmChart-for-Argo.git
build:
commands:
- echo "Generating unique IMAGE_TAG based on timestamp..."
- export IMAGE_TAG=$(date +%Y%m%d%H%M%S)
- echo "Generated IMAGE_TAG"
- echo Building the backend JAR...
- ./gradlew clean bootJar --exclude-task test
- echo "Build completed, checking for JAR file:"
- ls build/libs/ # build/libs 경로의 파일 목록을 출력하여 JAR 파일 생성 확인
- test -f build/libs/*.jar || { echo "JAR file not found"; exit 1; }
- cp build/libs/users-0.0.1-SNAPSHOT.jar app.jar # Dockerfile에서 사용하기 위해 app.jar로 복사
- echo "Docker build 시작"
- docker build -t $ECR_URL/$BACKEND_ECR_REPO:$IMAGE_TAG .
- docker tag $ECR_URL/$BACKEND_ECR_REPO:$IMAGE_TAG $ECR_URL/$BACKEND_ECR_REPO:$IMAGE_TAG
post_build:
commands:
- echo Build completed on date
- echo Pushing Docker image to ECR with tag $IMAGE_TAG...
- docker push $ECR_URL/$BACKEND_ECR_REPO:$IMAGE_TAG
- echo Updating Chart version in Chart.yaml...
- yq eval '.version = "'$IMAGE_TAG'"' -i HelmChart-for-Argo/helm-charts/Chart.yaml
- echo Updating backend image tag in values.yaml...
- yq eval '.backend.services[0].image.tag = "'$IMAGE_TAG'"' -i HelmChart-for-Argo/helm-charts/values.yaml
- yq eval '.backendTimestamp = "'$IMAGE_TAG'"' -i HelmChart-for-Argo/helm-charts/values.yaml
- echo Packaging Helm chart...
- cd HelmChart-for-Argo
- helm package ./helm-charts -d output
- echo Generating Helm repository index...
- helm repo index output --url http://argocd-helm-repo.s3-website.ap-northeast-2.amazonaws.com
- echo Uploading Helm chart and index to S3...
- aws s3 cp output/ s3://argocd-helm-repo/ --recursive
- echo Committing changes to values.yaml...
- git config --global user.name "CodeBuild"
- git config --global user.email "codebuild@example.com"
- git add ./helm-charts/values.yaml
- git commit -m "Update backendTimestamp to $IMAGE_TAG" at users || echo "No changes to commit"
- git push origin main || echo "No changes to push"
artifacts:
files:
- '**/*'
discard-paths: yes