My official account is MarkerHub and my website is Markerhub.com

For more selected articles, please click: Java Notes Complete.md

  • Author: LoyaltyLu
  • segmentfault.com/a/1190000019729005

The problem background

The company’s start-up technical team, without any infrastructure, needed to build a series of code management and automated deployment tools… So triggered the following series of deployment process, lasted for two days, also encountered various problems in the middle, but finally built all the basic tools successfully, yeah ~, let’s take a look at the building process.

resources

Server 1, CentOS, the company gave a low configuration server as a temporary server, there is no way, so do it.

Thinking: If I use the traditional yum to install, I will definitely be a mess, and it is not convenient for myself to manage and maintain, I choose Dokcer in dilemma, maybe some friends ask what Docker is and how to use, do not worry about the portal:

Segmentfault.com/a/119000001…

Test environment setup

In order to quickly build a PHP test environment, I decided to use Laradock. Although there are a lot of files, but the things encapsulated in laradock are relatively complete. I don’t know what technology will be used in the later development, so I decided to use laradock first.

Laradock’s official documentation also provides a comprehensive introduction. The way I use here is to deploy multiple sets of projects. The directory structure is as follows:

+ laradock
+ project-1
+ project-2


Copy the code

Start using:

1.git clone https://github.com/laradock/laradock

2.cp env-example .env

Env configuration can be modified, can be adjusted according to their own situation

3.docker-compose up -d nginx php-fpm mysql redis

You can add any programs you want to start, such as RabbitMQ, Mongo, etc., to the end if you need to start, the first time to start is a bit long

4.docker-compose exec --user=laradock workspace bash

For projects such as Laravel, composer is a must. Execute this command to enter the workspace and perform composer

5.docker-compose exec nginx nginx -s reload

I’m sure some people will ask me if I have to go into the nginx container and restart it every time I change the nginx configuration, or if I have to restart the entire container. Where is the nginx configuration file:./laradock/nginx/sites/

Let’s just run it and try it out.

GitLab

Now that the running environment has been set up, how should I store the code? In fact, there are many choices according to their actual situation, such as GitHub, code cloud, GitLab, etc. I chose GitLab. At the beginning, I did not find that Laradock actually provides GitLab service. You’re on your own. It’s easy.

docker \ run -d \ -p 443:443 \ -p 8080:80 \ -p 222:22 \ --name gitlab \ --restart always \ -v /home/gitlab/config:/etc/gitlab \ -v /home/gitlab/logs:/var/log/gitlab \ -v /home/gitlab/data:/var/opt/gitlab \ Gitlab /gitlab-ce Port 443, host 8080-> container 80, host 222-> container 22 This is to mount the disk, mount the host directory to the container, so that my content will not be lost even if the container is broken. #gitlab/gitlab-ce this is the image to start. If the image does not exist, Docker will automatically download the latest versionCopy the code

After the container is successfully started, there will be a period of time to start GitLab. When you see the container is successfully started, you cannot access it immediately. You just need to wait a little while.

Gitlab_rails ['gitlab_ssh_host'] = 'host IP'# Host IP address gitlab_rails['gitlab_shell_ssh_port'] = 222# SSH port external_URL exposed to the host 'domain name '# The domain name assigned to gitlab can be reverse proxy to port 8080 using NginxCopy the code

Jenkins

There are many ways to implement automated deployment such as webhook, Jenkins, Travis CI, etc. My choice is Jenkins because it was used in previous deployments. Laradock still provides Jenkins service because it did not realize that it built a… Looks like we’re gonna have to take a closer look next time.

docker run -d \ --name myjenkins \ -p 8181:8080 \ -p 50000:50000 \ -v /home/jenkins/:/var/jenkins_home \ jenkins/jenkins #-p: exposed port, host 8181-> container 8080, host 50000-> container 50000 #-v Mount the /var/jenkins_home directory to the /var/jenkins_home directoryCopy the code

Is it also very simple ~. ~, but Jenkins will have an initial password after the installation is successful. How to check the initial password? There are two ways:

Docker logs < your container name > so that you can see the contents of the container output / home/Jenkins/secrets/good/home/Jenkins initialAdminPassword# here need to replace your mounted directoryCopy the code

Jenkins configuration

Initialize the

Input the initialization password you have obtained above. The next step I choose is recommended installation. If you need it later, you can go to the plug-in library to install it.

Plug-in installation

After successful initialization, go to System Settings -> Plug-in Management to install a few necessary plug-ins:

Publish Over SSH GitLab Plugin # Publish Over SSH GitLab Plugin # Publish Over SSH GitLab Plugin # Publish Over SSH GitLab Plugin # Publish Over SSH GitLab Plugin #Copy the code

Start a journey

1. Basic configuration

After installing the plug-in, you need to configure some basic content such as JDK, Node, SSH, and so on

1. SSH installed

Go to: Manage Jenkins-> Configure System

Click Advanced:

Click Test Configuration to Test whether the connection is successful

2. The JDK, git

Go to Manage Jenkins-> Global Tool Configuration

I use automatic installation of JDK and Git, JDK installation requires an account, to register under it

3. Nodejs installation

Second, create a project

  • Create a new project

  • Choose free style

Three, configuration engineering

Set the maximum number of builds to be reserved

Use git source tool, enter git address, add git user

if [ -f "test.tar.gz" ]; then rm testv.tar.gz fi tar -zcvf test.tar.gz ./*Copy the code

SSH does not support folder transfer, so you need to package the content and unpack it to the server

Save it all and build it. Yeah ~

Thank you for watching

I haven’t written an article for a long time. This is a long one. Thank you for your patience in reading it.

Recommended reading

Java Notes Complete.md

Great, this Java site, everything! https://markerhub.com

The UP master of this B station, speaks Java really good!

Too great! The latest edition of Java programming ideas can be viewed online!