轻量级git服务器 Gogs git 服务器搭建

gogs搭建教程:
原文链接:
https://garthwaite.org/docker-gogs.html

内容:
Dockerized Gogs git server and alpine postgres in 20 minutes or less
// under docker

I’ve babysat gitlab omnibus before and it wasn’t any fun. So when a group of volunteer developers decide to rewrite a community website “with devops” I did what is becoming an annual exercise looking for a free many-user private git repo.

Unsatisfied with bitbucket and friends I decided to try docker + gogs.

$ docker pull gogs/gogs
$ docker images gogs/gogs
REPOSITORY TAG IMAGE ID CREATED SIZE
gogs/gogs latest 40ce39eb7c4b 2 weeks ago 81.17 MB
The image is about 81MB and based on Alpine Linux which is perfect, it saves me from forking the repo and doing that myself.

$ docker run --rm --name gogs gogs/gogs
Apr 8 00:03:03 syslogd started: BusyBox v1.24.1
2016/04/08 00:03:03 [W] Custom config ‘/data/gogs/conf/app.ini’ not found, ignore this if you’re running first time
2016/04/08 00:03:03 [T] Custom path: /data/gogs
2016/04/08 00:03:03 [T] Log path: /app/gogs/log
2016/04/08 00:03:03 [I] Gogs: Go Git Service 0.9.15.0323
2016/04/08 00:03:03 [I] Log Mode: Console(Trace)
2016/04/08 00:03:03 [I] Cache Service Enabled
2016/04/08 00:03:03 [I] Session Service Enabled
2016/04/08 00:03:03 [I] SQLite3 Supported
2016/04/08 00:03:03 [I] Run Mode: Development
2016/04/08 00:03:03 [I] Listen: http://0.0.0.0:3000
Apr 8 00:03:03 sshd[31]: Server listening on 0.0.0.0 port 22.
Note that this docker image listens on two ports: gogs on 3000 and ssh on 22. Usually running ssh in a container is considered bad form but in this case we are supporting git-over-ssh. Let’s kill this container and restart it properly.

$ docker stop gogs; docker rm gogs
$ mkdir -p /srv/lxc/gogs/data
$ docker run -d --name gogs \
  -p 8300:3000 -p 8322:22 -v /srv/lxc/gogs/data:/data gogs/gogs

Let’s take a look at that web service: open http://vault:8300 gogs start page

Things are going so well at this point that I feel emboldened - what is it like running postgres in docker nowadays?

$ docker pull postgres

… starts downloading two hundred something MB …

200MB for just a database manager? Not in my digital backyard. A search for docker alpine postgresturns up kiasaki/alpine-postgres in not one but practically all of the results.

$ docker pull kiasaki/alpine-postgress
$ docker images kiasaki/alpine-postgres

REPOSITORY TAG IMAGE ID CREATED SIZE
kiasaki/alpine-postgres latest b58856735da8 5 weeks ago 22.69 MB
The docker hub page for kiasaki/alpine-postgres shows how to start the image:

$ mkdir -p /srv/lxc/postgres/data
$ docker run -d --name postgres \
  -e POSTGRES_PASSWORD=supersecret \
  -v /srv/lxc/postgres/data:/var/lib/postgresql/data \
  -p 5432:5432 kiasaki/alpine-postgres

$ docker ps -s | grep postgres

b33cf374af70 kiasaki/alpine-postgres “/docker-entrypoint.s” 7 minutes ago
Up 7 minutes 0.0.0.0:5432->5432/tcp postgres 48 B (virtual 22.69 MB)
22 MB < 200 MB and stack-smashing protection for postgres to boot.

At this point we could spin up the gogs container and use the postgres superuser but lets see how we go about administrating postgres without installing psql.

$ docker exec -it postgres psql -U postgres

psql (9.4.6, server 9.5.1)
WARNING: psql major version 9.4, server major version 9.5.
         Some psql features might not work.
Type "help" for help.

postgres=# CREATE USER gogs WITH PASSWORD '^go4git&docker';
CREATE ROLE
postgres=# CREATE DATABASE gogs OWNER gogs;
CREATE DATABASE
postgres=# \q
Great now we spin up gogs this time linking it to postgres and data volumes:

$ docker stop gogs; docker rm gogs
$ docker run --link postgres -d --name gogs
-p 8300:3000 -p 8322:22 -v /srv/lxc/gogs/data:/data gogs/gogs
$ open https://vault:8300

Back at the start page select [[postgres]] with user:gogs pass:^go4git&docker I found a hiccup here - after filling in the credentials it created the DB but forwarded my client to localhost:3000 and not vault:8300 (in my case).

From here I made an account dang and it was nice enough to pull in my gravatar. I made an empty repo called 'blog' then added http://vault:8300/dang/blog.git as a remote to my existing repo:

$ git remote add gogs http://dang@vault:8300/dang/blog.git
$ git push gogs master

Password for 'http://dang@vault:8300':
Voila! I can make and push branches then turn those into pull requests in gogs. Remember you can peak at the logs of either container:

$ docker logs -f gogs
$ docker logs -f postgres

Suggestions on how better to explore and learn docker are always welcome in the comments.

Credits: Thanks to Manuel Carlos Rodriguez for some corrections.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值