์ด์ ์ ์์ฑํด๋๊ณ ์ค์งํ gitlab์๋ฒ(GCP), jenkins/tomcat์๋ฒ(aws) ์์ํ๊ณ ์งํ.
โ๏ธ ์ด๋ฆ : docker-host
โ๏ธ ์ด๋ฏธ์ง : amazon linux 2
โ๏ธ ์ ํ : t2.micro
โ๏ธ ํคํ์ด ์ ํ
โ๏ธ ๋คํธ์ํฌ : MY-VPC, PUB2C
โ๏ธ ๋ณด์๊ทธ๋ฃน : DEV-SG
โ๏ธ ์ฌ์ฉ์๋ฐ์ดํฐ :
#!/bin/bash
timedatectl set-timezone Asia/Seoul
hostnamectl set-hostname docker-host
amazon-linux-extras install docker -y
systemctl enable --now docker
curl https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
usermod -a -G docker ec2-user
โ๏ธ IP๋งตํ
docker host, jenkins server mobaxtermํตํด CLIํ๊ฒฝ ์ง์ .
โ๏ธ docker ์ค์น ์ ๋์๋์ง ํ์ธ
[ec2-user@docker-host ~]$ docker version
โ๏ธ docker host์์ ๋ช ๋ น์ด๋ก ํตํฉํ๊ธฐ (1)
sudo passwd ec2-user ##ํค ๋์ ํจ์ค์๋๋ก jenkins์ ์ฐ๊ฒฐ๋ ์ ์๋๋ก ํจ์ค์๋ ์ค์
sudo vi /etc/ssh/sshd_config
PasswordAuthentication yes
#PermitEmptyPasswords no
#PasswordAuthentication no
sudo systemctl restart sshd
->์ธ์ ๋์๋ค๊ฐ ์ ์ํ๋ฉด ํค ์์ด ํจ์ค์๋๋ก ์ ์ ๊ฐ๋ฅ.
โ๏ธ docker host์์ ๋ช ๋ น์ด๋ก ํตํฉํ๊ธฐ (2)
sudo mkdir /opt/docker
sudo vi /opt/docker/Dockerfile
FROM tomcat:9
RUN cp -R /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps ##์ปจํ
์ด๋ ์์ชฝ์์ ๋๋ค๋ฅธ ์ปจํ
์ด๋ ๊ฒฝ๋ก๋ก ๋ณด๋ด๊ธฐ ;
COPY ./*.war /usr/local/tomcat/webapps ##๋์ปค ํธ์คํธ์ ์๋ ๊ฒ์ ์ปจํ
์ด๋ ์์ชฝ์ผ๋ก ์นดํผ.
sudo chown -R ec2-user:ec2-user /opt/docker/
โ๏ธ RUN cp -R /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps
์ด์
[ec2-user@docker-host ~]$ docker run -d -p 8080:8080 --name test-tomcat tomcat:9
## dockerport:tomcatport
[ec2-user@docker-host ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5602886b782b tomcat:9 "catalina.sh run" 15 seconds ago Up 14 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp test-tomcat
์์ ๋ด์ฉ๋ฌผ์ด ์์ด์ ํ๋ฉด์ด ์ ๋ธ.
[ec2-user@docker-host ~]$ docker exec -it test-tomcat bash
root@5602886b782b:/usr/local/tomcat# ls
bin conf lib logs NOTICE RELEASE-NOTES temp webapps.dist
BUILDING.txt CONTRIBUTING.md LICENSE native-jni-lib README.md RUNNING.txt webapps
root@5602886b782b:/usr/local/tomcat# cp -R webapps.dist/* webapps
dist์ ์๋ ๋ด์ฉ์ webappsํด๋๋ก ์ฎ๊ฒจ์ฃผ๋ฉด ์ฒซ ํ์ด์ง๊ฐ ๊นจ์ง๋ ๊ฒ์ ๋ง์ ์ ์์.
[ec2-user@docker-host ~]$ docker rm -f test-tomcat
test-tomcat
ํ ์คํธ ๋ง๋ฌด๋ฆฌ
โ๏ธ jenkins๋๋ฉ์ธ:8080์ผ๋ก ์ง์ - ๋ก๊ทธ์ธ ํ Jenkins ๊ด๋ฆฌ - ํ๋ฌ๊ทธ์ธ ๊ด๋ฆฌ - ์ค์น ๊ฐ๋ฅ - publish over ssh๊ฒ์ - ์ฒดํฌํ๊ณ install without restart
โ๏ธ jenkins๊ด๋ฆฌ - ์์คํ
์ค์ - ๋งจ ํ๋จ SSH Servers - ์ถ๊ฐ - name: docker-host ; hostname:docker.lovemj.shop ; username:ec-user ๊ณ ๊ธ - Use password authentication, or use a different key ์ฒดํฌ ๋ฐ์ค ์ฒดํฌ ; Password์นธ์ password ์
๋ ฅ, ๋งจ ํ๋จ์ Test configuration ํด๋ฆญ, Success ํ์ธ. - apply,์ ์ฅ
โ๏ธ jenkins dashboard - ์ฌ๋ก์ด ์์ดํ
- ์ด๋ฆ : BuildAndDeployOnContainer - copyfrom : BuildAndDeployjob - ๋๋จธ์ง ๊ทธ๋๋ก (gitlab์ฌ๋ผ์์๋ค๋ฉด , ์์ฌ๋ ธ์ผ๋ฉด github๋ก ๊ฒฝ๋ก ๋ฐ๊พธ๊ณ ) ๋งจ ํ๋จ ๋น๋ ํ ์กฐ์น ๊ธฐ์กด ๊ฒ ์ญ์ ํ๊ณ send build artifacts over SSH ์ ํ - SSH server name; docker-host - source files; webapp/target/*.war
- remove prefix; webapp/target
- exec command ;
cd /opt/docker;
docker build -t mj030kk/mytomcat:v1.0 .;
docker rm -f docker-container;
docker run -d -p 8080:8080 --name docker-container mj030kk/mytomcat:v1.0
docker rm -f docker-container;
์ ์ด์ ; ๋ค์ ๋น๋ ๋ ๋ ์ปจํ
์ด๋ ์ด๋ฆ๊ณผ ํฌํธ๊ฐ ์ค๋ณต๋๋ฏ๋ก ์ด์ ์ ์์ฑ๋ ๊ฒ์ ์ง์์ค์ผํจ.โ๏ธ๋์๋ณด๋ - ์ง๊ธ ๋น๋ ํ docker.lovemj.shop:8080/webapp/์ผ๋ก ์ง์
r2com@DESKTOP-DD3FU43 MINGW64 ~
$ rm -rf dev-site/
r2com@DESKTOP-DD3FU43 MINGW64 ~
$ git clone -b master http://gitlab.lovemj.shop/mangji/dev-site.git
r2com@DESKTOP-DD3FU43 MINGW64 ~
$ cd dev-site
r2com@DESKTOP-DD3FU43 MINGW64 ~/dev-site (master)
$ cd webapp/src/main/webapp/
r2com@DESKTOP-DD3FU43 MINGW64 ~/dev-site/webapp/src/main/webapp (master)
$ vi index.jsp
->๋ฌธ๊ตฌ ์์
r2com@DESKTOP-DD3FU43 MINGW64 ~/dev-site/webapp/src/main/webapp (master)
$ git add index.jsp
r2com@DESKTOP-DD3FU43 MINGW64 ~/dev-site/webapp/src/main/webapp (master)
$ git commit -m "modify index.jsp"
[master 8164efb] modify index.jsp
1 file changed, 1 insertion(+), 1 deletion(-)
r2com@DESKTOP-DD3FU43 MINGW64 ~/dev-site/webapp/src/main/webapp (master)
$ git push -uf origin master
โ๏ธ ๋ฆฌํฌ์งํ ๋ฆฌ - ๋ฆฌํฌ์งํ ๋ฆฌ ์์ฑ - ์ด๋ฆ : git-test - ์์ฑ
โ๏ธ ๋ฏธ๋ฆฌ ๋ง๋ค์ด๋ docker ์ฌ์ฉ์ ํ์ธ ๋ฐ ์ง์
โ๏ธ ๋ณด์์๊ฒฉ์ฆ๋ช
ํด๋ฆญ - AWS CodeCommit์ ๋ํ HTTPS Git ์๊ฒฉ ์ฆ๋ช
- ์๊ฒฉ์ฆ๋ช
์์ฑ
์๊ฒฉ์ฆ๋ช
๋ค์ด๋ก๋, ๋น๋ฐ๋ฒํธ ํ์
ํด๋ฆฝ๋ณด๋์ ๋ฆฌํฌ์งํ ๋ฆฌ ์ฃผ์ HTTPS ๋ณต์ ํ git bash์์ ํด๋ก ์งํ.
r2com@DESKTOP-DD3FU43 MINGW64 ~
$ git clone https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/git-test
Cloning into 'git-test'...
warning: You appear to have cloned an empty repository.
iam์์ ๋์๋ ID์ ๋น๋ฐ๋ฒํธ ๋ฃ์ด์ ์๊ฒฉ์ฆ๋ช ์๋ฃ.
r2com@DESKTOP-DD3FU43 MINGW64 ~
$ cd git-test
r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ ls -al
total 20
drwxr-xr-x 1 r2com 197121 0 Aug 2 11:47 ./
drwxr-xr-x 1 r2com 197121 0 Aug 2 11:47 ../
drwxr-xr-x 1 r2com 197121 0 Aug 2 12:06 .git/
-> .git/ ์ด ์๋ค๋ ๊ฒ์ init , config ํ ํ์ ์๋ค๋ ๊ฒ.
r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ echo "Hello World" > README.txt
r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git add README.txt
warning: in the working copy of 'README.txt', LF will be replaced by CRLF the next time Git touches it
r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git commit -m "add site"
[master (root-commit) 0d03f92] add site
1 file changed, 1 insertion(+)
create mode 100644 README.txt
r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git remote
origin
r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git push origin master
gitbash์์ ์งํ
mkdir git-migration
git clone --mirror http://gitlab.lovemj.shop/mangji/dev-site.git git-migration ##git lab ์ฃผ์
cd git-migration/
git push -uf https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/git-test --all ## codedommit ๋ฆฌํฌ์ง ์ฃผ์
โ๏ธ ๋์๋ณด๋ - newitem - ์ด๋ฆ: BuildAndDeployOnContainerWithCodecommit - copy from : BuildAndDeployOnContainer - OK
โ๏ธ ์ค๋ช : ์ฝ๋ ์ปค๋ฐ์์ ์ฝ๋๋ฅผ ๊ฐ์ง๊ณ ์ค๊ณ ๋ฉ์ด๋ธ์ผ๋ก ์ฝ๋๋ฅผ ๋น๋ํ๊ณ ๋์ปค ํธ์คํธ๋ก ๋ฐฐํฌํ์
โ๏ธ์์ค์ฝ๋ ๊ด๋ฆฌ ; ๋ฆฌํฌ์งํ ๋ฆฌ URL : https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/git-test
credential ;
Add(Jenkins)
kind:username with password
username, password ; IAM์ ๋ณด์์ ๊ฐ์ ธ์ค๊ธฐ - Add
โ๏ธ๋ง๋ ํฌ๋ฆฌ๋ด์
์ ํํ๊ณ apply,์ ์ฅ
โ๏ธ๋น๋์๋ฃ!
r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ cd ~
r2com@DESKTOP-DD3FU43 MINGW64 ~
$ rm -rf git-test/
r2com@DESKTOP-DD3FU43 MINGW64 ~
$ git clone https://git-codecommit.ap-northeast-2.amazonaws.com/v1/repos/git-test
r2com@DESKTOP-DD3FU43 MINGW64 ~
$ cd git-test/
r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ vi webapp/src/main/webapp/index.jsp
r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git add .
r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git commit -m "codecommit"
[master ce14734] codecommit
1 file changed, 1 insertion(+), 1 deletion(-)
r2com@DESKTOP-DD3FU43 MINGW64 ~/git-test (master)
$ git push -uf origin master
โ๏ธ ์ง๊ธ ๋น๋ ํ ํ์ธ