by Devin Yang
(This article was automatically translated.)

Published - 6 years ago ( Updated - 6 years ago )


How to quickly set up an out-of-the-box Gogs environment?
This article introduces the use of docker-compose.yml to quickly establish a gogs environment.

If you want to play around, you can download it from my repo and try it out:


On the MacOs system, basically a very standard docker-compose command is enough:
docker-compose up -d

There is absolutely no need to create a database or to install screens and any settings.

After startup, you can use a browser to open localhost:10080 to register.

The first registered user is the system administrator.

I did a preliminary test, and this set currently meets my needs. Compared with gitlab, gogs is simpler.

The soruce code encoded in the big5 file can also be displayed normally after setting etc/app.ini.

Here are the official configuration instructions:

About Architecture

Why use the host mount method for folders such as /etc/app.ini and git instead of volume mount.

My reasons are as follows:

1. I do not want to share the mounted data to the remote host.

Second, it is better for me to perform incremental rsync backups in the same directory.

Three, you can easily modify the configuration files.
For example, add Open Ssh public-private key pair , config and other settings in the git/.ssh directory.

4. It is easier to share to different containers or adjust the post-recieive of git.

Simple git push deployment

Since I use the D-Laravel container environment for development, this machine has the same environment as the official one.
Therefore, after confirming that there is no problem on the local machine, push directly, and through the post-receive hook,
Immediately deploy to the formal environment.

/sites is the project folder, gogs and D-Laravel's container share this folder.

When gogs is on the same host as the formal environment


How to deploy remotely? Here is my method.

If you are not very clear about how to set up ssh public key authentication , please Google keywords to learn by yourself.
1. First generate the public-private key pair of oepn ssh and put it into the git/.ssh directory.
id_rsa (private key) (public key)
config (connection settings)

2. Directly use the docker-compose command to enter the git user environment of gogs. The command is as follows:
docker-compose exec -u git web bash
It needs to be executed in the directory or subdirectory of gogs. This command will use a recursive method to find whether there is a docker-compose.yml configuration file in the directory.
Here -u represents, I use the git user in the container to execute bash.
web is the service name defined in docker-compose.yml .

3. In the gogs container, enter the project to be deployed remotely
cd ~/gogs-repositories/<組織>/<專案>.git/hooks

4. Add the remote push in the last line of hooks. The demoserver here is the name set in config (connection setting).

The config content of ssh is as follows:

5. On the remote source, set the environment for checking the source to production.
GIT_WORK_TREE=/sites/ccc git checkout -f

6. Therefore, when you push in your own environment, you can see information similar to the following to complete the remote deployment.
Here I use zsh, so there are simple gss, gaa, gcmsg and other aliases for commit actions.

The process in the above figure is roughly like this:
Client (your own computer) ==> push to gogs repo ===> hooks of gogs are pushed to remote demoserver ==> post-receive hook of remote demoserver will checkout the latest revision to the official environment.

The above scenarios are just for reference, you can deploy in any way you can think of, such as rsync..
Here, I will not discuss security issues, such as firewall-related settings, or how to set sshd_config, such as AllowUsers git@
Or the .git directory should not be in the DocumentRoot folder of the web page,
If you use the Laravel framework, you should not encounter this problem, because .git will be in the project directory, not public.


Tags: docker git

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


Install docker-compose on ubuntu

Briefly introduce how I installed docker-compose on ubuntu. Quite easy.


Docker container formatted display

I think if you want to write some automation functions, it may be useful to be able to format the output container content. The following are some reference examples of Docker container formatting and display instructions


How to execute X client and X Window in Container (docker gui)

Today I will talk to you about X, not iPhone X, nor X-Men, but X Window System, He is the main graphical interface display component of the current Linux system. Since it is very easy to expand and modularize, it has been used since it was established in 1986. The X Window system adopts the Client/Server architecture, which splits the application program and the display into two. The application program of X Windows is usually called X Client, and the display is the well-known X Server. The X client communicates with the X server through the X protocol (X protocol), which is an asynchronous network communication protocol.