도커허브 주소 바꾸기!!!
Dockerfile 작성
tomcat 이미지에 Java Project 아카이브 파일(webapp.war)을 특정 경로에 복사
출처: https://hub.docker.com/_/tomcat
docker/Dockerfile
From tomcat:9-jre11
COPY ./webapp.war /usr/local/tomcat/webapps
Ansible Playbook 작성
Dockerhub 로그인과 Docker Image 빌드와 업로드를 위한 Ansible Playbook 작성.
Dockerhub 로그인을 위한 TOKEN은 Jenkins에서 Password Parameter로 입력, Docker Image 태그 관리를 위한 BUILD_NUMBER를 젠킨스가 자동으로 입력.
출처: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
playbook/docker_build_and_push.yaml
- hosts: ansible_host
gather_facts: no
tasks:
- name: Login to Docker Hub
docker_login:
username: 도커허브계정
password: "{{ lookup('env', 'TOKEN') }}"
reauthorize: yes
- name: Build and Push Image
docker_image:
build:
path: /home/vagrant/java-hello-world
name: 도커허브 Repository 주소
tag: "{{ lookup('env', 'BUILD_NUMBER') }}"
push: yes
source: build