CI/CD์ ๋ชฉ์
์๋์ ์์ ์ GITLAB์ pushํ๋ฉด ๋ณ๊ฒฝ๋ ๋ด์ฉ์ด ๋น๋๊น์ง ๋ฐ์๋๊ฒ ํ๋ ๊ฒ, ์ฆ, ๋น๋์ ํ ์คํธ ๊ทธ๋ฆฌ๊ณ ๋ฐฐํฌ๊น์ง ์๋ํํด์ฃผ๋ ๊ฒ์ด CI/CD์ ๋ชฉ์ ์ด๋ค.
sudo su -
cd ๋ฐฐํฌํ๊ณ ์ถ์ ํ๋ก์ ํธ ๋ค์ด๊ฐ๊ธฐ
git pull
docker build -t ์ด๋ฆ .
docker images
docker stop ๊ธฐ์กด container_id
docker run <project ์ด๋ฆ> <new version>
- ๋ฌธ์ ๋ Build Server(ex. gitlab-runner)์ ์ค์ ๋ฐฐํฌ๋๋ ์๋ฒ(ex. aws ec2)๋ ๋ค๋ฅผ ์ ์๋ค.
- ์ด๋ฅผ ์ํด, Container Registry๋ฅผ ํตํด Docker Image๋ฅผ ์ ์ฅํ ์ ์๋ค.
๐จ๏ธ ์ ํํด์ผ๋ ์์ : Dockerfile์ด ํ๋ก์ ํธ์ ์์ด์ผํ๋ค.
Dockerfile
FROM gradle:7.4-jdk11-alpine as builder
WORKDIR /build
# ๊ทธ๋๋ค ํ์ผ์ด ๋ณ๊ฒฝ๋์์ ๋๋ง ์๋กญ๊ฒ ์์กดํจํค์ง ๋ค์ด๋ก๋ ๋ฐ๊ฒํจ.
COPY build.gradle settings.gradle /build/
RUN gradle build -x test --parallel --continue > /dev/null 2>&1 || true
# ๋น๋ ์ด๋ฏธ์ง์์ ์ ํ๋ฆฌ์ผ์ด์
๋น๋
COPY . /build
RUN gradle build -x test --parallel
# APP
FROM openjdk:11.0-slim
WORKDIR /app
# ๋น๋ ์ด๋ฏธ์ง์์ jar ํ์ผ๋ง ๋ณต์ฌ
COPY --from=builder /build/build/libs/*-SNAPSHOT.jar ./app.jar
EXPOSE 8080
# root ๋์ nobody ๊ถํ์ผ๋ก ์คํ
USER nobody
ENTRYPOINT [ \
"java", \
"-jar", \
"-Djava.security.egd=file:/dev/./urandom", \
"-Dsun.net.inetaddr.ttl=0", \
"app.jar" \
]
๐จ๏ธ ๋ณ์์ถ๊ฐ settings - cicd - variables(expand) - add variable
-
Docker build์์
gradle ๋น๋
๋ฅผ ํ์ ๊ฒฝ์ฐ.gitlab-ci.yml
- docker build๋ฅผ gitlab-runner(๋ฆฌ๋ ์ค ์๋ฒ) ๊ฐ ๋์ ํด์ค๋ค.# stage โ ๋จ๊ณ stages: - dockerbuild-push package: image: docker:latest stage: dockerbuild-push services: - docker:dind before_script: - docker login registry.gitlab.com -u $GITLAB_USER -p $GITLAB_PASSWORD script: - docker build -t registry.gitlab.com/$GITLAB_USER/$PROJECT_NAME . - docker push registry.gitlab.com/$GITLAB_USER/$PROJECT_NAME after_script: - docker logout
-
Docker build ์์
gradle build๋ฅผ ํ์ง ์๋
๊ฒฝ์ฐ.gitlab-ci.yml
stages: - build - dockerbuild-push build: image: openjdk:11.0-slim stage: build script: - ./gradlew clean - ./gradlew build -x test before_script: - chmod +x gradlew artifacts: paths: - build/libs/*.jar expire_in: 8 min package: image: docker:latest stage: dockerbuild-push services: - docker:dind before_script: - docker login registry.gitlab.com -u $GITLAB_USER -p $GITLAB_PW script: - docker build -t registry.gitlab.com/$GITLAB_USER/<project-name> . - docker push registry.gitlab.com/$GITLAB_USER/<project-name> after_script: - docker logout
-
์คํ๊ณผ์
๋ฆฌ๋ ์ค ์คํฌ๋ฆฝํธ ์คํ
- ๊ฒฐ๊ณผ
CI/CD > Jobs
๋ฐฐํฌ ํ์ธ ๋ฉ์ผ
Leave a comment