Friday, October 4, 2019

How to setup Jenkin Container for building docker image and deploy application to Google Cloud

I Start jenkin original

1. Follow this link and then you can start your jenkin container
https://jenkins.io/doc/book/installing/

docker run -u root --rm -p 9090:8080 -p 50000:50000 -v D:\Jenkins-Data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean

II Custom jenkin
At this custom I will add kubectl into custom image that for using kubectl later to create deployment and expose service in Google Cloud.

1. Dockerfile
FROM jenkinsci/blueocean

User root

COPY --from=lachlanevenson/k8s-kubectl:v1.10.3 /usr/local/bin/kubectl /usr/local/bin/kubectl

EXPOSE 8080 50000

Build container

docker build -t myjenkin .

Run

docker run -u root --rm -p 9090:8080 -p 50000:50000 -v D:\Jenkins-Data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock myjenkin

3. Run jenkin
3.1. Access url localhost:9090 from browser and you set it up like a normal



4. Plugin required
docker-build-step
Google OAuth Credentials
Google Container Registry Auth
Google Kubernetes Engine


5. Config maven tool
{Jenkin} -> {Manage Jenkins} -> {Global Tool Configuration} -> Add maven




And add Maven Integration Plugin

6. Create service account in google and get json credential
- Create new service account and add permission


Add permission you want here I add full access api permission



And then go to access service download json credential that use for jenkin later



7. Create maven job build

I have a simple project in github
https://github.com/maidanhcongtu/zapier-app



Push image in post step


Create credential for google account




Add deploy  to google k8s


Note: When you got error can not fetch project id you need to enable api Resource Management API in google


Now you can save but can not start the job build there is one last step for config build container.

8. Config build 
Expose docker Daemon from setting


And add uri build for docker
{Jenkin} -> {Manage Jenkins} -> {Configure System} -> {Docker Builder}

Add uri: unix:///var/run/docker.sock
or url 127.0.0.1:2375

Now you can run the job build

No comments:

Post a Comment