From f3f7e7f723d2c4783ac1cc2c23f3e1594550c912 Mon Sep 17 00:00:00 2001 From: Przemyslaw Ozgo Date: Wed, 30 Mar 2016 21:08:20 +0100 Subject: [PATCH] First Commit --- Dockerfile | 16 +++ README.md | 118 +++++++++++++++++- circle.yml | 22 ++++ container-files/config/init/start.sh | 14 +++ .../etc/nginx/hosts.d/gitbucket.conf | 28 +++++ .../etc/nginx/nginx.d/99-cache.conf | 1 + .../etc/supervisor.d/gitbucket.conf | 3 + docker-cloud.yml | 5 + 8 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 circle.yml create mode 100644 container-files/config/init/start.sh create mode 100644 container-files/etc/nginx/hosts.d/gitbucket.conf create mode 100644 container-files/etc/nginx/nginx.d/99-cache.conf create mode 100644 container-files/etc/supervisor.d/gitbucket.conf create mode 100644 docker-cloud.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..957dc0d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM million12/nginx +MAINTAINER Przemyslaw Ozgo linux@ozgo.info + +ENV GITBUCKET_VERSION=3.12 \ + HOSTNAME=localhost \ + CONTEXTPATH="" \ + DATA_DIR=/data/gitbucket + +RUN \ + rpm --rebuilddb && yum clean all && \ + yum install -y java-1.8.0-openjdk wget && \ + wget -L -O /opt/gitbucket.war https://github.com/gitbucket/gitbucket/releases/download/${GITBUCKET_VERSION}/gitbucket.war + +COPY container-files/ / + +EXPOSE 80 81 443 \ No newline at end of file diff --git a/README.md b/README.md index 5ba3f02..60faaac 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,116 @@ -# docker-gitbucket -GitBucket in Docker +### GitBucker in Docker (Nginx/HTTP2) + +[![CircleCI Build Status](https://img.shields.io/circleci/project/million12/docker-gitbucket/master.svg)](https://circleci.com/gh/millio12/docker-bitbucket) +[![GitHub Open Issues](https://img.shields.io/github/issues/million12/docker-gitbucket.svg)](https://github.com/million12/docker-gitbucket/issues) +[![GitHub Stars](https://img.shields.io/github/stars/million12/docker-gitbucket.svg)](https://github.com/million12/docker-gitbucket) +[![GitHub Forks](https://img.shields.io/github/forks/million12/docker-gitbucket.svg)](https://github.com/million12/docker-gitbucket) +[![Stars on Docker Hub](https://img.shields.io/docker/stars/million12/gitbucket.svg)](https://hub.docker.com/r/million12/gitbucket) +[![Pulls on Docker Hub](https://img.shields.io/docker/pulls/million12/gitbucket.svg)](https://hub.docker.com/r/million12/gitbucket) +[![Docker Layers](https://badge.imagelayers.io/million12/gitbucket:latest.svg)](https://hub.docker.com/r/million12/gitbucket) + + [![Deploy to Docker Cloud](https://files.cloud.docker.com/images/deploy-to-dockercloud.svg)](https://cloud.docker.com/stack/deploy/?repo=https://github.com/million12/docker-gitbucket/tree/master) + +[Docker Image](https://registry.hub.docker.com/u/million12/gitbucket/) with GitBucket server using [million12/nginx](https://hub.docker.com/r/million12/nginx/) docker image as base. (HTTP2 and HAProxy SSL termination ready.) + + +### Environmental Variable + +- `CONTEXTPATH` runtime variable `--prefix=` +- `HOSTNAME` runtime variable `--host=` +- `DATA_DIR` runtime variable `--gitbucket.home=` + +#### Nginx Features + +##### - HTTP/2 support +Container is built with `http/2` support and by default it listens on port `443`. +Make sure you open it on `docker run`. +Port `81` is used by default for load balancing (`HAProxy`) ssl termination. + +##### - dummy SSL certificates +The default *catch-all* vhost is configured to work on HTTPS as well. + +##### - error logging + +Nginx `error_log` is set to `stderr` and therefore Nginx log is available only via `docker logs [contaienr]`, together with supervisor logs. + +This is probably best approach if you'd like to source your logs from outside the container (e.g. via `docker logs` or CoreOS `journald`) and you don't want to worry about logging and log management inside your container. + +##### - graceful reload after config change + +Folders `/etc/nginx/` and `/data/conf/nginx/` are monitored for any config changes and, when they happen, Nginx is gracefully reloaded. + +##### - Nginx status page + +Nginx status page is configured under `/nginx_status` URL on the default vhost. Also see `STATUS_PAGE_ALLOWED_IP` env variable described below. +Eample output: + + Active connections: 1 + server accepts handled requests + 11475 11475 13566 + Reading: 0 Writing: 1 Waiting: 0 + +### Usage + + docker run \ + -d \ + --name gitbucket \ + -p 80:80 \ + -p 443:443 \ + million12/gitbucket + +Mount data to host os and edit some variables. + + docker run \ + -d \ + --name gitbucket \ + -p 80:80 \ + -p 443:443 \ + -e HOSTNAME=myhostanme.com \ + -e DATA_DIR=/my/custom/container/dir \ + -v /my/host/dir:/my/custom/container/dir \ + million12/gitbucket + +### Build + + docker build -t million12/gitbucket . + +### Access GitBucket web interface + +- HTTP: http://docker.ip +- SSL/HTTP2: https://docker.ip + +**Default Login and Password is `root:root`** + +Docker troubleshooting +====================== + +Use docker command to see if all required containers are up and running: +``` +$ docker ps +``` + +Check logs of gitbucket server container: +``` +$ docker logs gitbucket +``` + +Sometimes you might just want to review how things are deployed inside a running + container, you can do this by executing a _bash shell_ through _docker's + exec_ command: +``` +docker exec -ti gitbucket /bin/bash +``` + +History of an image and size of layers: +``` +docker history --no-trunc=true million12/gitbucket | tr -s ' ' | tail -n+2 | awk -F " ago " '{print $2}' +``` + +## Author + +Author: Przemyslaw Ozgo () + +--- + +**Sponsored by [Prototype Brewery](http://prototypebrewery.io/)** - the new prototyping tool for building highly-interactive prototypes of your website or web app. Built on top of [Neos CMS](https://www.neos.io/) and [Zurb Foundation](http://foundation.zurb.com/) framework. + diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..88ffd14 --- /dev/null +++ b/circle.yml @@ -0,0 +1,22 @@ +machine: + services: + - docker + +dependencies: + pre: + - docker info && docker version + +test: + pre: + - docker build -t million12/gitbucket . + + override: + # Start Gitbucket + - docker run -d -p 80:80 -p 443:443 --name gitbucket million12/gitbucket + - docker logs -f gitbucket | tee -a ${CIRCLE_ARTIFACTS}/gitbucket.log: + background: true + - while true; do if grep "Started ServerConnector" -a ${CIRCLE_ARTIFACTS}/gitbucket.log; then break; else sleep 1; fi done + # Check connection on port 80 + - curl -sSLi --head http://127.0.0.1/ | grep "HTTP/1.1 200 OK" + # Check connection on port 443 + - curl -sSLi --insecure --head https://127.0.0.1/ | grep "HTTP/1.1 200 OK" \ No newline at end of file diff --git a/container-files/config/init/start.sh b/container-files/config/init/start.sh new file mode 100644 index 0000000..765eb75 --- /dev/null +++ b/container-files/config/init/start.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -eu +export TERM=xterm +# Bash Colors +green=`tput setaf 2` +bold=`tput bold` +reset=`tput sgr0` +log() { + if [[ "$@" ]]; then echo "${bold}${green}[LOG `date +'%T'`]${reset} $@"; + else echo; fi +} +log "Creating Cache directory for nginx" +mkdir -p /var/lib/nginx/ +log "Starting GitBucket" diff --git a/container-files/etc/nginx/hosts.d/gitbucket.conf b/container-files/etc/nginx/hosts.d/gitbucket.conf new file mode 100644 index 0000000..fb21ce2 --- /dev/null +++ b/container-files/etc/nginx/hosts.d/gitbucket.conf @@ -0,0 +1,28 @@ +server { + listen 80 default_server; + listen 81 default_server http2 proxy_protocol; ## Needed when behind HAProxy with SSL termination + HTTP/2 support + listen 443 default_server ssl http2; + + ssl_certificate /etc/nginx/ssl/dummy.crt; + ssl_certificate_key /etc/nginx/ssl/dummy.key; + + location / { + proxy_pass http://localhost:8080; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_connect_timeout 150; + proxy_send_timeout 100; + proxy_read_timeout 100; + proxy_buffers 4 32k; + client_max_body_size 500m; # Big number is we can post big commits. + client_body_buffer_size 128k; + } + location /assets/ { + proxy_pass http://localhost:8080/assets/; + proxy_cache cache; + proxy_cache_key $host$uri$is_args$args; + proxy_cache_valid 200 301 302 1d; + expires 1d; + } +} diff --git a/container-files/etc/nginx/nginx.d/99-cache.conf b/container-files/etc/nginx/nginx.d/99-cache.conf new file mode 100644 index 0000000..0b74747 --- /dev/null +++ b/container-files/etc/nginx/nginx.d/99-cache.conf @@ -0,0 +1 @@ +proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=cache:512m inactive=1d max_size=60g; diff --git a/container-files/etc/supervisor.d/gitbucket.conf b/container-files/etc/supervisor.d/gitbucket.conf new file mode 100644 index 0000000..32885ea --- /dev/null +++ b/container-files/etc/supervisor.d/gitbucket.conf @@ -0,0 +1,3 @@ +[program:gitbucket] +command = /usr/bin/java -jar /opt/gitbucket.war --host=%(ENV_HOSTNAME)s --prefix=%(ENV_CONTEXTPATH)s --gitbucket.home=%(ENV_DATA_DIR)s +autorestart = true \ No newline at end of file diff --git a/docker-cloud.yml b/docker-cloud.yml new file mode 100644 index 0000000..9b8ffae --- /dev/null +++ b/docker-cloud.yml @@ -0,0 +1,5 @@ +gitbucket: + image: million12/gitbucket + ports: + - "80:80" + - "443:443" \ No newline at end of file