The first time I work in a small team on an internal corporate project. Examine the git more or less mastered. Now I suffer with delay. The bottom line is:

We use the standard branch scheme (master, develop, topic). We program and type in our local computer. There is a combat server. It is also a git server. He is also a test server :) The server contains 2 web applications. We pull the first one from the master branch - the release is ready, the second one - from develop - we test it before we master the bullet.

So, in order to tritely put a tiny feature change of the branch into production (or at least into the test) I have to overcome the routine:

  1. Switch from feature to develop, update branch.
  2. Merge feature, push develop
  3. Switch to master, update it
  4. Keep develop, run master
  5. Connect to the combat server to do a pull on the develop application
  6. Connect to the combat server to make a pool on the master application
  7. ???
  8. "And then correct the letter, please"
  9. goto 1

Is it possible to somehow all beg? I'm sure doing something wrong.

  • Tell me, and when the application is still some other actions are performed? Set file permissions, clean logs, web server reboot? - Nick Volynkin
  • @NickVolynkin 1) And how to do better, tell me? The project is intracorporate, and this server is literally in the next room and is used by 500-1000 people (not a day, but in general). 2) No. Some service things we do on the krone, and not at the Deploy. We also have gulp and fill in the minimized files, for example. - GroZa
  • Do I really understand that on the server there are just two different folders with git-repositories and from these folders are distributed, respectively, test and combat version of the site? - Nick Volynkin
  • About Gulp - do you add or minimize source files in git? Or both? Is the developer or server minimized? - Nick Volynkin
  • There is a common bare-git repository where we push and pull. And so you are right. Fighting and test are just 2 local folders configured for a pull from this git repository. - GroZa

2 answers 2

Points 1-2 is a very simplified (where for example testing is removed) the process that each developer does. This is his usual cycle.

Paragraph 3-4 is release. He does not have to do the usual developer. He becomes a release manager (or responsible person assigned to it). It is not done for everyone, but according to the process - once every two weeks or twice a day .

Items 5-8 are made by pressing one (maximum two buttons) or by running a single script. It runs on a special build server ( for a small company like this, it can be one machine for building, testing, and repository). The build script itself usually does the following

  • git clone / git archive
  • running a script that fixes configs, templates (you don’t want to show all programmers passwords to the database on the prod?)
  • running a script that processes css minimizes js and the like.
  • run unit tests (they are here, since there may be problems after minimization :))
  • archiving and archiving in a safe place
  • connect to the prod server (s) and upload the archive there.
  • The archive is unpacked on the server in a separate folder, the nginx / apache config or symlink is corrected and the server restarts. (You can of course stop the server, rub the files and start the server, but if something went wrong ...).
  • the minimum tests on the prode are sold (for example, that the main page returns 200 code, and not 500).
  • and the git adds a tag with a release link.

This script is written once and then podganyatsya as needed.

Also, this script should be supplemented, so that it could work with the develop branch.

Now we simplify life. In the hooks on the git server, we add this skrpit, so that when pushing in the devel / master machine, it starts up and, as a result, is deposited on the test server / prod. Merge in the master of ordinary programmers is prohibited.

Now everything looks like this. The developer took the feature, made a branch for it, did it. After the merde in the devel (or through the merge requester), his code automatically pours out onto the test environment. If suddenly it happened that he broke everything - he should fix it.

If this does not work, you can run the script on CI - one of the most popular - jenkins. As a result of the warmth, it is just to press one button.

Q / A

  • why not bullet directly on the combat server? If someone leads the server, he will have access to the full development history. It is necessary?
  • no one will lead me to the history of the gita, so I will be a bullet. already been
  • Why how many difficulties with the script? And imagine that the bug was found in the middle of the night and you need to fix it urgently. The presence of such a script greatly simplifies life.
  • Is it possible without tests? can. But it is better to make some minimal ones.
  • "Point 3-4 is a release." - unfortunately, in reality it does not work. Touch the master every 1-2 days. We set the level task and change the logo in the hat for New Year's - and so that it will be available for dinner. - GroZa
  • Thank. And so everything is cool. I will look at Jenkins. Always wanted to learn. - GroZa
  • In fact, no one bothers to make a release all the time. But the New Year's cap is done via hotfix with a config that can be turned off. Next time you only need to fix the config. - KoVadim
  • that is, I understand correctly that in order to change one line in the code in production, the script will archive the entire project and transfer it by deleting the old one, run tests, clean temporary files, etc., when I update only the changed files using the pool in 5 seconds? Or somehow it can be simplified? - GroZa
  • Yes, you understand correctly. But not until the end. Well, if you have only one server and two scripts. Then you can do nothing more. And if the farm is 300 cars? And if it so happened that the hoster decided to "lie down". And what if you want a release before rolling out to protest? Sometimes, even the correction of a single line can lead to such complex and hard-to-find bugs ... removing the old one, just not. No need to delete. Not enough, suddenly you need to roll back. - KoVadim

Let's separate the entities first. In the process involved:

  • Battle server.
  • Test server.
  • Git server
  • Some "deployment agent". Now you are deploying (deploying) with your hands, it would be nice to delegate this task to a continuous integration server (CI server). In the simplest version, this is implemented by hooks on the git server.
  • Application source code
  • Distribution of the application - in your case these are files minimized with the help of Gulp.

At the moment, the tasks of all servers are performed by one, and the distribution is stored with the code. Let us nevertheless treat them as separate and strive for low connectivity between them (as in the PLO between classes). This will give our system flexibility and much greater scalability. In particular, we will not rely on the fact that something lies side by side on the same disk or is accessible over a local network.

What should be done:

  1. Separate the distribution from the code. When we commit, we run gulp, we get minimized files, (optionally) we pack them into the archive, move them to the server and deploy them there. Minimized code does not need to be stored, because we can always get it from the source.
  2. Implement the deployment scenarios in the code . At least provide a place for the actions performed on the server: filling configs, restarting services, etc. As mentioned above, this is done via git-hook and / or the CI server.
  3. Automate the response to changes in the repository: when pushing to certain branches, it should be deployed in a specific environment. Since the deployment script is now in our code, we can.

And in the organization of work:

  1. Revise the order of releases. Now you seem to release every typo and everyone can release. It is also worth thinking about the protection of the master branch (including from its careless actions).

Working example

I propose to conduct an experiment on the example of GitLab.com (ie, we will use the cloud service). The choice is subjective, here are the arguments for:

  1. There is an opportunity to create free private repositories. (Ie your commercial code is in relative safety.)
  2. Included is a GitLab CI, tightly integrated with the repository.
  3. Free runners are available (including private repositories) - conditionally, virtual machines on which we will perform our tasks.

The argument against: if the project grows, someday the free license will not be enough for all tasks.

A working example with pipelines and logs is posted on GitLab.com .

The main file describing the script being executed is in the root folder of the project and is called .gitlab-ci.yml .

 image: alpine stages: - gulp - test - package - deploy cache: paths: - node_modules/ gulp: stage: gulp image: node:latest before_script: - npm install script: node_modules/.bin/gulp compress artifacts: paths: - dist expire_in: 10 minutes test: stage: test script: ls dist script: echo 'run tests here' package: stage: package script: tar -czvf packaged.tar.gz dist artifacts: paths: - packaged.tar.gz deploy_prod: stage: deploy script: echo 'deploy on master' only: - master deploy_test: stage: deploy script: echo 'deploy on develop' only: - develop 

We will place the dependencies in the config for npm - package.json . The gulpfile.js file describes the compress task that minimizes.

Screenshot of the CI pipeline window:

enter image description here

Result of work: archive packaged.tar.gz , in it dists/hello.js , in it

 !function(t,e,i){t.title="New title"}(window,document); 
  • That's right. OK. I agree. It is necessary to separate flies from cutlets. It is necessary to do a minification when unloading min files only - this will be a distribution in some way. Nevertheless, the deployment process itself causes pain. What simple CI can you advise? - GroZa
  • And is it bad to pull changes to the battle of the gita? - GroZa
  • @GroZa I advise this one. about.gitlab.com/gitlab-com . Now I will write an example about him. - Nick Volynkin
  • @GroZa if not difficult, add to the question the commands with which you gulp using. And then I specifically did not work with him. - Nick Volynkin