A foundation set up automated deployment process
gitlabdockernginxjenkinsphp
read for about 10 minutes
background to the issue
start-up company technical team, without any infrastructure, it is necessary to build a series of code management and deployment automation tools ... so
led to the following series of deployment, which lasted Two days later, the middle is also encountered various problems, but in the end all the basic tools to build success, yeah, here we look together with the build process.
Resource
Server One, CentOS, the company gave a lower server configuration when the temporary server, no way, so do it.
Question: If I use yum to install the traditional, I will certainly be loaded mess, not to facilitate their management and maintenance, in the case of a dilemma I chose Dokcer, there may be some small partner asked what Docker is how to use, do not panic there are portal: Linux docker-compose combat, [Advanced article] docker bad choreography PHP development environment
, test environment
Image Caption
In order to quickly set up a test environment I decided to use PHP laradock, though many documents, but something inside the package is relatively wide, and late-stage development do not know what technology will be used, it was decided to use this, get ready to start with service.
laradock official document to the introduction is also very comprehensive, the way I used here is a way to deploy multiple sets of project directory structure is as follows:
- laradock
- project-1
- project-2
started:
Git clone https://github.com/laradock/l...
CP-Example .env the env
env can be modified configuration which can be adjusted according to its own
docker-compose up -d nginx php- fpm mysql redis
You can later add the program to start, like rabbitmq, mongo, etc., need additional time can start at the end, for the first time start-up time is a bit long
docker-compose exec --user = laradock workspace bash
Like laravel projects must ultimately composer, execute this command into the work area, you can perform the composer
docker-compose exec nginx nginx -s reload
Sure some people will ask me to change the nginx configuration is not always have to go into the container nginx restart or reboot the entire containers Yeah, unused, you can execute this command to restart the nginx. Where nginx site configuration file in it: ./ laradock / nginx / sites /
run first try.
GitLab
now operating environment has been set up well, how should I store the code does, in fact, there are a lot of options to start according to their actual situation, such as: GitHub, the code cloud, GitLab etc., I chose GitLab, beginning no GitLab found laradock actually provide the service. . Toss to fend for themselves, it is actually very simple.
Docker
RUN -d
-p 443: 443
-p 8080: 80
-p 222: 22 is
-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
# of parameters:
# -d: let container background
# -p: exposure port, the port 443 is directed to sink the container host 443, host 8080> container 80, the host 222-> container 22
# host port can customize according to their own situation
# -name to your container from a name, they do not and can duplicate the existing
when # -restart when the container exit docker whether to restart the
# -v this is to mount the disk, and the directory of the host to mount a container, the container to do so even if it is bad my content is not lost.
# Host / home / gitlab / config directory is mounted to the container / etc / gitlab directory, host directory according to its own set
# gitlab / gitlab-ce this is to start the mirror if the mirror does not exist, docker will automatically download new
After the successful launch container there will be a time to start GitLab, immediately saw the successful launch of the visit is not accessible, a little wait on it, the configuration file in the directory you specified host can be modified, need to be amended as follows :
IP address gitlab_rails [ 'gitlab_ssh_host'] = 'host IP' # host computer
gitlab_rails [ 'gitlab_shell_ssh_port'] = 222 # exposed to the host's ssh port
external_url 'domain' domain # assigned to gitlab may be used nginx do trans to the proxy port to 8080
Jenkins
automate deployment there are many ways such as: webhook, Jenkins, Travis CI and so on, my choice is Jenkins, because it is still used prior to deployment with this here, laradock Jenkins still provides the service, and just I could not find myself to build one. . . It seems more than the next first look at the hands.
RUN -d Docker
-name myjenkins
-p 8181: 8080
-p 50000: 50000
-v / Home / Jenkins /: / var / jenkins_home
Jenkins / Jenkins
# Parameter Description
# -d: let container background
# -p: exposed ports, host 8181-> 8080 containers, host 50000-> container 50000
# mount -v this is the disk, and the directory of the host to mount a container, the container to do so even if it is bad I will not be lost content .
# Host / home / jenkins / directory is mounted into the container / var / jenkins_home directory, directory host according to its own set
is not very simple . But Jenkins after a successful installation will have a initialization code, how to initialize the password to view it, there are two ways:
# The first way
docker logs <your container name> # container output so you can see the contents of
# second way
cat / home / jenkins / secrets / initialAdminPassword # good here / home / jenkins need to replace your mount directory
jenkins configuration
initialization
clipboard.png
Enter you get to the top of the initialization code, the next step I chose the recommended installation, back they need they can go to the library plug-in installation.
Plug-in installation
After successful initialization Go to System Settings -> Plug-in Manager to install a few necessary plug-ins:
Publish Over SSH
GitLab Plugin # Gitlab because it is used so to install this
NodeJS Plugin # our front-end node of Vue so use to
begin the journey of
a basic configuration
You need to configure some basic content such as jdk, node, ssh, etc. After installing the plug-in
ssh installation
enter: Manage Jenkins-> Configure System
clipboard.png
Click Advanced:
clipboard.png
Click Test Configuration to test whether the connection is successful
jdk、git
进入:Manage Jenkins-> Global Tool Configuration
clipboard.png
I'm here jdk, git automatic installation, jdk installed when required an account, you can go to the next register
nodejs installation
clipboard.png
]
Second, create a project
clipboard.png
Create a new project
the freedom to choose the style
Third, configuration engineering
clipboard.png
Set retain up to several versions build
clipboard.png
Use git source tools, enter the address git, git add user
clipboard.png
IF [-f "test.tar.gz"]; the then
RM testv.tar.gz
fi
tar -zcvf test.tar.gz ./*
here why the project should pack it, because you want to configure ssh below does not support folders transport, it is necessary to package first and then to the content server unpacking
clipboard.png
Save all you can to build up. Yeah
thank you to watch
for a long time did not write the article, this lengthy, thank you patience to watch, I hope for your help, I hope you will offer different opinions, to find a more efficient way to complete, thank you!