by Devin Yang
(This article was automatically translated.)

Published - 7 years ago ( Updated - 7 years ago )

foreword

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:
https://github.com/DevinY/gogs

illustrate

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.
ANSI_CHARSET= big5

 
Here are the official configuration instructions:
https://gogs.io/docs/advanced/configuration_cheat_sheet

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

post-receive

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)
id_rsa.pub (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.
#!/bin/sh
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


docker

Install docker-compose on ubuntu

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

docker

How to start HAProxy with Docker on Raspberry

Raspberry is very cheap and has quite a lot of applications, for example, some people use it as a Wi-Fi router, For game consoles, monitors and many other IoT-related applications, I use it as a HAProxy. Long story short, since I have an old Windows server running old versions of PHP and Apache, and can't set up HTTPS certificates, I wanted to say Help through HAProxy. Let this old server also have https URL, So to share my docker-compose.yml configuration.

git

Yesterday's report of git alias

We can use git config --global alias.[alias] to "reduce the long and long git subcommands that are often executed" into simplified aliases. So you can also add your frequently used git commands to the global git alias through the git alias setting. Let's take a look at my practical example of how to reduce long subcommands into easy-to-use aliases.