未加星标

Make your own Raspberry Pi git repository server with Gogs and Docker

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

The Raspberry Pi is an amazing little computer that, while it's targeted at the DIY Hardware Maker, it is a full-fledged linux computer that can be used to run services that used to require much bigger and more expensive computers. How long ago were office servers required to be $4000 systems from the likes of Dell Computers? It seems that the Raspberry Pi (and other tiny computers) can perform the same tasks at a low cost with minuscule energy requirements. To this end I'm setting up Gogs (a github-like server for Git repositories) on a Raspberry Pi. As I worked on the project it seemed most straightforward to use Docker to manage the Gogs process, and therefore the project became setting up Docker on Raspberry Pi to run other services.

While there have been experimental Docker implementations on Raspbian or other Raspberry Pi-focused distro's, in August the Raspberry Pi Foundation announced with the Docker organization official support for Docker on Raspbian . This is cool because it's so easy to build a small network of Raspberry Pi's, and Docker Swarm makes it easy to set up a slew of systems with an array of services. Even if you wouldn't use Raspberry Pi's in production (using an SD-drive based system for production use sounds silly) it's feasible to use them for low cost experimentation or in situations where downtime (e.g. dead SD card) is not a problem.

Because the Raspberry Pi is an ARM system, and the vast majority of Docker images are for Intel x86 systems, we'll have to carefully pick the Docker images for ARM. Fortunately there is an ARM image for Gogs (gogs/gogs-rpi).

Setting up Docker on Raspbian

You should have first installed Raspbian on your Raspberry Pi - I assume you know how to do this, but if not the instructions are on the raspberrypi.org website.

Installing Docker is now as easy as the following:

$ curl -sSL https://get.docker.com | sh

A suggested first thing to kick the tires of Docker is this :

$ docker run -ti resin/rpi-raspbian:jessie-20160831 /bin/bash

[email protected]:/# cat /etc/issue

Raspbian GNU/Linux 8 \n \l

[email protected]:/# exit

Making sure Docker runs when the system reboots

That didn't make sure Docker began when the system rebooted.

Follow the instructions here: https://docs.docker.com/engine/admin/systemd/

$ sudo systemctl start docker $ sudo systemctl enable docker Installing Gogs

The documentation for running Gogs in Docker is here: https://github.com/gogits/gogs/tree/master/docker

However, it is written assuming an Intel x86 based Linux, but we have an ARM system. Therefore we must modify the instructions a little, and we also want this container to automatically start on system reboot.

$ docker pull gogs/gogs-rpi

This is the Raspberry Pi Gogs image. This is our first deviation from the official instructions.

$ mkdir -p /var/gogs

Make the suggested directory for holding Gogs data.

$ docker run --name=gogs --restart always -p 10022:22 -p 80:3000 -v /var/gogs:/data gogs/gogs-rpi

The "--restart always" flag configures the restart policy so it will, as implied, restart the service automatically. The next argument configures port mapping for the SSH service so it'll appear at port 10022, which will be important when using an SSH URL to access a Git repository. The next makes the service appear on port 80. The next tells Gogs to use the data directory we made. The last references the correct image.

This will start Gogs interactively showing you an activity log. You'll be able to access the service at http://localhost while running a browser ON the Raspberry Pi, or else specifying the IP address of the Raspberry Pi while on another computer.

You go through the normal setup of Gogs at this point. I configured it to use SQLITE3 as the database because there isn't a mysql available. Otherwise the options are left as default. After you reach the Gogs login page you'll need to create a user account - and note this will be the first user account on that server, and therefore it will have administrator privileges.

You can if you like go through creating a Git repository on this server, import another repository, etc.

$ docker start gogs

You can kill the interactive Gogs container, and then restart it this way non-interactively.

You can also reboot the computer and make sure that both the Docker service and the Gogs container restarted automatically.

Extra Credit -- Adding storage to the Raspberry Pi

It's not a good idea to trust an SD-card based computer to be reliable. Therefore it's useful to set up a plan to add more reliable storage to the Raspberry Pi and/or automatically backup the repositories to a reliable server.

I haven't done this yet - and will update this post when I do - but I plan the following:

Add a USB drive to the Raspberry Pi for external storage Use "git clone --mirror" for all repositories to send them to a directory on my Drobo Set up a permanent mount in /etc/fstab for the Drobo

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: Raspberry PiDockerLinuxGitSQLMySQLSwarm
分页:12
转载请注明
本文标题:Make your own Raspberry Pi git repository server with Gogs and Docker
本站链接:http://www.codesec.net/view/483015.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(41)