.travis.yml ํ์ผ์ ์์ฑํ๋ ๋ชจ๋ ๊ณผ์ ๋ค์ ํธ๋ฌ๋ธ์ํ ํ๋ฉด์ ํฌ์คํ ํด๋ณด๊ฒ ๋ค..
๊ธด ์ฌ์ ์ด ๋ ๋ฏ..
์์ง ์ด๋ฏธ์ง ํ์ผ ๋ฐ ์ปดํฌ๋ํธ ์ค์ ํ์ผ๋ฑ์ ๋ฐฐํฌ๋ ํ์ง๋ชปํด์ EC2์ ๋ฐฐํฌ ํ ์คํ์ ์ผ๋จ ์๋์ผ๋ก ํ๋ ๊ฒ์ ๋ชฉํ๋ก ํ์๋ค.
Travis CI ๋น๋ ์คํ
์ด์ง : https://docs.travis-ci.com/user/build-stages/
Travis CI CodeDeploy: https://docs.travis-ci.com/user/deployment/codedeploy/
Travis CI rake aborted: https://travis-ci.community/t/no-rakefile-found-when-adding-travis-to-a-github-project/3520
https://devlog-wjdrbs96.tistory.com/317
https://devlog-wjdrbs96.tistory.com/search/%EB%AC%B4%EC%A4%91%EB%8B%A8%20%EB%B0%B0%ED%8F%AC%ED%95%98%EA%B8%B0
์ฐพ์ ๋ดค๋ ๋๋ถ๋ถ์ .travis.yml ํ์ผ๋ค์ ๋ชจ๋ ํฐ ๋จ์์ ํ ๋ธ๋ญ์ ๋ค์ด๊ฐ ์์์...
๋ญ๊ฐ travis.yml ํ์ผ ๋ด์์๋ ๊ฐ ๋จ๊ณ๋ณ๋ก ์์
์ ์ํํ ์ ์๋ ๋ฐฉ๋ฒ์ด ๋ฐ๋ก ์๋๊ฐ? ๊ณ ๋ฏผํด์ GPT์๊ฒ๋ ๋ฌผ์ด๋ณด์๋ค.
๊ทธ๋ฐ ๊ณผ์ ์์ .travis.yml ํ์ผ ์์์ ์ํฌํ๋ก์ฐ๋ฅผ ์ ์ํ๋ ๋ฐฉ๋ฒ์ jobs, include, stage ๋ธ๋ญ์ ์ฌ์ฉํ๋ ๊ฒ์ด์๋ค.
jobs:
include:
- stage: SpringBoot gradle build
language: java
jdk:
- openjdk11
cache:
directories:
- '$HOME/ .m2/repository'
- '$HOME/ .gradle'
before_install:
- chmod +x gradlew
script:
- ./gradlew clean build
before_deploy:
- zip -r prac-built ./docker-compose.yml
- mkdir -p deploy
- mv prac-built.zip deploy/prac-built.zip
- stage: Build Docker image
sudo: required
language: generic
services:
- docker
script:
- docker build -t $SPRING-REPO -f ./Dockerfile .
- docker build -t $NGINX-REPO -f ./Dockerfile-nginx .
- docker login -u $DOCKER_USER -p $DOCKER_PASS
- docker push $SPRING-REPO
- docker push $NGINX-REPO
- stage: Deploy to EC2
deploy:
- provider: s3
access_key_id: $AWS_ACCESS_KEY
secret_access_key: $AWS_ACCESS_SECRET
bucket: practice-build
region: ap-northeast-2
skip_cleanup: true
acl: private
local_dir: deploy
wait-until-deployed: true
- provider: codedeploy
access_key_id: $AWS_ACCESS_KEY
secret_access_key: $AWS_ACCESS_SECRET
bucket: practice-build
key: SpringBoot.zip
bundle_type: zip
application: practiceservice
deployment_group: practiceservice-group
region: ap-northeast-2
wait-until-deployed: true
We were unable to parse one of your secure environment variables. Please make sure to escape special characters such as ' ' (white space) and $ (dollar symbol) with \ (backslash) . For example, thi$isanexample would be typed as thi\$isanexample. See https://docs.travis-ci.com/user/encryption-keys.
ํ๊ฒฝ ๋ณ์๋ฅผ ์ง์ ํ ๋ ๋ ํฌ์ด๋ฆ์ ๋
ธ์ถ ์ํค์ง ์์ผ๋ ค๊ณ SPRING-REPO, NGINX-REPO ์ด๋ฐ์์ผ๋ก ์ด๋ฆ์ ์คฌ์๋ค.
๋ค๋ฅธ ํ๊ฒฝ๋ณ์๋ _(์ธ๋๋ฐ)๋ฅผ ์ ์ฌ์ฉํด๋๊ณ ํด๋น ํ๊ฒฝ๋ณ์์ -(ํ์ดํ)์ ์จ๋ฒ๋ ค์ Travis CI๊ฐ ๋์ํ๋ ์์ค์ ์ด๋ฅผ ์๋ณํ์ง ๋ชปํ๊ฒ... -(ํ์ดํ)์ \_(์ธ๋๋ฐ)๋ก
๋ฐ๊ฟ์ฃผ์๋ค.
์ฒซ ๋ฒ์งธ๋ก ์ฌ๋ ธ์ ๋ .jar ํ์ผ ๋น๋๋ ์ฑ๊ณตํ์ง๋ง, ๋์ปค ์ด๋ฏธ์ง ๋น๋์, ํธ์์์ ์ค๋ฅ๊ฐ ๋ฌ์๋ค. ๊ทธ๋์ Travis CI ๋ก๊ทธ๋ฅผ ํ์ธํด๋ณด๋
์๊ฐํ๋ ๊ฐ์ ์ด ๋ง์๊ณ , ์ด์ ๋จ๊ณ์์ ์๋ฌด๋ฆฌ ๋น๋๋ฅผ ์ฑ๊ณตํ๊ณ .jarํ์ผ์ ๋ง๋ค์ด๋
FROM openjdk:11 ARG JAR_FILE=build/libs/*.jar COPY ${JAR_FILE} app.jar ENTRYPOINT ["java","-jar", "-Dspring.profiles.active=${active}", "-Duser.timezone=Asia/Seoul", "/app.jar"]
๋ค์ ๋จ๊ณ์์๋ ๋ค๋ฅธ ํ๊ฒฝ์์ ์คํ๋๊ธฐ ๋๋ฌธ์ ํด๋น ๋์ปคํ์ผ์ด ๋ฐ๋ผ๋ณผ .jarํ์ผ์ ์ฐพ์ ์ ์๋ค๋ ๊ฒ...
Travis CI ๊ณต์ ๋ฌธ์- ๋น๋ ๋จ๊ณ
๊ทธ๋์ ํด๊ฒฐํ๋ ค๋ฉด, .jarํ์ผ์ gradle์ ํตํด ๋น๋ํ์๋ง์ ๊ฐ์ ์์
๋จ์์์ ๋์ปค ์ด๋ฏธ์ง ๋น๋ ํ ๋์ปค ํ๋ธ์ ๋ฐ๋ก ํธ์
ํด์ผ ๊ฒ ๋ค๊ณ ์๊ฐํด์ "Docker Build Image" stage์ ์คํ๋ง๋ถํธ ํ๋ก์ ํธ๋ฅผ ๋์ปค ๋น๋ ํ๋ ๋ถ๋ถ์ ์ฒ์ stage๋ก ์ฎ๊ฒจ์ ๊ฐ์ด ๋์ ํ๋๋ก ๋ฐ๊ฟจ๋ค.
after_script: ์์๋ ๋จ์ ๋ช ๋ น์ด๋ง ์์ฑํ์ฌ์ผํจ.
before_deploy:
- zip -r prac-built ./docker-compose.yml
- mkdir -p deploy
- mv prac-built.zip deploy/prac-built.zip
jobs:
include:
- stage: SpringBoot gradle build & Build Gradle Docker Image
language: java
jdk:
- openjdk11
#cache:
# directories:
# - '$HOME/ .m2/repository'
# - '$HOME/ .gradle'
before_install:
- chmod +x gradlew
script:
- ./gradlew clean build
- sudo systemctl start docker
- docker build -t $SPRING_REPO -f ./Dockerfile .
- echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
- docker push $SPRING_REPO
- stage: Build Nginx Docker image
sudo: required
language: generic
services:
- docker
script:
- docker build -t $NGINX_REPO -f ./Dockerfile-nginx .
- echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
- docker push $NGINX_REPO
- stage: Deploy to EC2
deploy:
- provider: s3
access_key_id: $AWS_ACCESS_KEY
secret_access_key: $AWS_ACCESS_SECRET
bucket: practice-build
region: ap-northeast-2
skip_cleanup: true
acl: private
local_dir: deploy
wait-until-deployed: true
- provider: codedeploy
access_key_id: $AWS_ACCESS_KEY
secret_access_key: $AWS_ACCESS_SECRET
bucket: practice-build
key: SpringBoot.zip
bundle_type: zip
application: practiceservice
deployment_group: practiceservice-group
region: ap-northeast-2
wait-until-deployed: true
์ด์ ๋์ปค ์ด๋ฏธ์ง ๋น๋ ๋ฐ ํธ์๊น์ง๋ ์๋๋๋ฐ ๋ฐฐํฌ๋ถ๋ถ์ด ๋ฌธ์ ์๋ค.. ์ด์ ์ ๋์ปค๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ๋จ์ S3 + CodeDeploy๋ฅผ ์ธ๋๋ rake aborted!
๋ผ๋ ์ค๋ฅ๋ฅผ ๋ณธ์ ์ด ์๋๋ฐ ์ ๋๋๊ฑด์ง ๋๋ฌด์ง ๋ ์ดํด๊ฐ ๋์ง ์์์..
https://travis-ci.community/t/no-rakefile-found-when-adding-travis-to-a-github-project/3520
3๋ฒ์งธ ์คํ ์ด์ง์์ language: ๋ฅผ ์ค์ ํด์ฃผ์ง ์์์ ๋ฐ์ํ ๋ฌธ์ ์์..
-> ํด๋น ์คํ ์ด์ง์ language: generic ์ ์ถ๊ฐํด์ค
branches:
only:
- master
services:
- docker
jobs:
include:
- stage: SpringBoot gradle build & Build Gradle Docker Image
language: java
jdk:
- openjdk11
#cache:
# directories:
# - '$HOME/ .m2/repository'
# - '$HOME/ .gradle'
before_install:
- chmod +x gradlew
script:
- ./gradlew clean build
- docker build -t $SPRING_REPO -f ./Dockerfile .
- echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
- docker push $SPRING_REPO
- stage: Build Nginx Docker image
sudo: required
language: generic
script:
- docker build -t $NGINX_REPO -f ./Dockerfile-nginx .
- echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
- docker push $NGINX_REPO
- stage: Deploy Stage
language: generic
before_deploy:
- zip -r prac-built ./docker-compose.yaml
- mkdir -p deploy
- mv prac-built.zip deploy/prac-built.zip
deploy:
- provider: s3
access_key_id: $AWS_ACCESS_KEY
secret_access_key: $AWS_ACCESS_SECRET
bucket: practice-build
region: ap-northeast-2
skip_cleanup: true
acl: private
local_dir: deploy
wait-until-deployed: true
- provider: codedeploy
access_key_id: $AWS_ACCESS_KEY
secret_access_key: $AWS_ACCESS_SECRET
bucket: practice-build
key: SpringBoot.zip
bundle_type: zip
application: practiceservice
deployment_group: practiceservice-group
region: ap-northeast-2
wait-until-deployed: true
S3์๋ ์ ์ฌ๋ผ๊ฐ๋๋ฐ Deploy ์์ ๋งํ๊ธธ๋ EC2 ์ธ์คํด์ค์์ ๋ก๊ทธ๋ฅผ ํ์ธํด ๋ณด์๋ค.
2023-09-20T08:57:25 ERROR [codedeploy-agent(2146)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: Aws::S3::Errors::NoSuchKey - The specified key does not exist.
ํค๊ฐ ์กด์ฌํ์ง ์์..
S3 ๋ฒํท์ ๋ค์ด๊ฐ ๋ฐฐํฌํ์ผ์ key ๊ฐ๊ณผ travis.yml ํ์ผ์ codedeploy ๋ธ๋ก์์์ key ๊ฐ์ ๋๊ฐ์ด ํด์ค์ผํ๋๋ฐ ์ค์๋ก ์ ์ ๋ง๋ค์๋ travis.yml ์ ์์ ํ์ง ์์์ ๋ฐ์ํ๋ ์ค๋ฅ์๋ค.
- provider: codedeploy access_key_id: $AWS_ACCESS_KEY secret_access_key: $AWS_ACCESS_SECRET bucket: practice-build key: SpringBoot.zip -> prac-build.zip bundle_type: zip application: practiceservice deployment_group: practiceservice-group region: ap-northeast-2 wait-until-deployed: true
2023-09-20 18:40:40.620 INFO 1 --- [nio-8081-exec-1] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header
Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: The HTTP header line [x-forwarded=Proto: http] does not conform to RFC 7230. The request has been rejected.
at org.apache.coyote.http11.Http11InputBuffer.skipLine(Http11InputBuffer.java:1074) ~[tomcat-embed-core-9.0.79.jar!/:na]
at org.apache.coyote.http11.Http11InputBuffer.parseHeader(Http11InputBuffer.java:905) ~[tomcat-embed-core-9.0.79.jar!/:na]
at org.apache.coyote.http11.Http11InputBuffer.parseHeaders(Http11InputBuffer.java:591) ~[tomcat-embed-core-9.0.79.jar!/:na]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:286) ~[tomcat-embed-core-9.0.79.jar!/:na]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) ~[tomcat-embed-core-9.0.79.jar!/:na]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:926) ~[tomcat-embed-core-9.0.79.jar!/:na]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1790) ~[tomcat-embed-core-9.0.79.jar!/:na]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-9.0.79.jar!/:na]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.79.jar!/:na]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.79.jar!/:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.79.jar!/:na]
at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]