From fcad2e5aea8acf8166471f40d5658f952502da2c Mon Sep 17 00:00:00 2001 From: syndbg Date: Tue, 24 Oct 2017 12:02:13 +0300 Subject: [PATCH] Add debian image --- Dockerfile.debian | 66 +++++++++++++++++++++++++++++++++++++++ docker/build-debian.sh | 29 +++++++++++++++++ docker/build-go-debian.sh | 31 ++++++++++++++++++ docker/s6/openssh/run | 22 +++++++++++-- docker/s6/syslogd/run | 7 ++++- 5 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 Dockerfile.debian create mode 100644 docker/build-debian.sh create mode 100644 docker/build-go-debian.sh diff --git a/Dockerfile.debian b/Dockerfile.debian new file mode 100644 index 000000000..d01416b09 --- /dev/null +++ b/Dockerfile.debian @@ -0,0 +1,66 @@ +FROM debian:9.2 + +# Install system utils & Gogs runtime dependencies +ADD https://github.com/tianon/gosu/releases/download/1.10/gosu-amd64 /usr/sbin/gosu +RUN chmod +x /usr/sbin/gosu && \ + apt update -q && \ + apt install -y \ + inetutils-syslogd \ + build-essential \ + ca-certificates \ + curl \ + wget \ + git \ + openssh-server \ + openssh-client \ + socat \ + uidmap \ + login \ + passwd \ + tzdata + +# NOTE: Symlink `syslogd` and fake `/dev/xconsole` since we don't have that. +RUN ln -s /usr/sbin/syslogd /sbin/syslogd && \ + mknod -m 640 /dev/xconsole p + +# NOTE: Install `skalibs` +ADD https://skarnet.org/software/skalibs/skalibs-2.6.0.2.tar.gz /tmp/skalibs +RUN cd /tmp/skalibs/skalibs-2.6.0.2 && \ + ./configure && make && make install && \ + cd - + +# NOTE: Install `execline` +ADD https://skarnet.org/software/execline/execline-2.3.0.3.tar.gz /tmp/execline +RUN cd /tmp/execline/execline-2.3.0.3 && \ + ./configure && make && make install && \ + cd - + +# NOTE: Install `s6` +ADD https://skarnet.org/software/s6/s6-2.6.1.1.tar.gz /tmp/s6 +RUN cd /tmp/s6/s6-2.6.1.1 && \ + ./configure && make && make install && \ + cd - + +ENV GOGS_CUSTOM /data/gogs + +# Configure LibC Name Service +COPY docker/nsswitch.conf /etc/nsswitch.conf +COPY docker /app/gogs/docker +COPY templates /app/gogs/templates +COPY public /app/gogs/public + +WORKDIR /app/gogs/build +COPY . . + +RUN chmod +x ./docker/build-go-debian.sh \ + ./docker/build-debian.sh \ + ./docker/finalize.sh && \ + ./docker/build-go-debian.sh \ + && ./docker/build-debian.sh \ + && ./docker/finalize.sh + +# Configure Docker Container +VOLUME ["/data"] +EXPOSE 22 3000 +ENTRYPOINT ["/app/gogs/docker/start.sh"] +CMD ["/bin/s6-svscan", "/app/gogs/docker/s6/"] diff --git a/docker/build-debian.sh b/docker/build-debian.sh new file mode 100644 index 000000000..3407472b4 --- /dev/null +++ b/docker/build-debian.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -x +set -e + +# Set temp environment vars +export GOPATH=/tmp/go +export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin +export GO15VENDOREXPERIMENT=1 + +# Install build deps +apt install -y libpam0g-dev + +# Build Gogs +mkdir -p ${GOPATH}/src/github.com/gogits/ +ln -s /app/gogs/build ${GOPATH}/src/github.com/gogits/gogs +cd ${GOPATH}/src/github.com/gogits/gogs +# Needed since git 2.9.3 or 2.9.4 +git config --global http.https://gopkg.in.followRedirects true +make build TAGS="sqlite cert pam" + +# Cleanup GOPATH +rm -r $GOPATH + +# Create git user for Gogs +addgroup --system git +useradd -o -u 0 -g git -M git -d /data/git -s /bin/bash && \ + usermod -p '*' git && \ + passwd -u git +echo "export GOGS_CUSTOM=${GOGS_CUSTOM}" >> /etc/profile diff --git a/docker/build-go-debian.sh b/docker/build-go-debian.sh new file mode 100644 index 000000000..232a5083d --- /dev/null +++ b/docker/build-go-debian.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Build GO version as specified in Dockerfile + +set -x +set -e + +# Components versions +export GOLANG_VERSION="1.8" +export GOLANG_SRC_URL="https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz" +export GOLANG_SRC_SHA256="406865f587b44be7092f206d73fc1de252600b79b3cacc587b74b5ef5c623596" + + +# Install build tools +apt install -y gcc musl-dev openssl golang-go + +export GOROOT_BOOTSTRAP="$(go env GOROOT)" + +# Download Go +wget -q "$GOLANG_SRC_URL" -O golang.tar.gz +echo "$GOLANG_SRC_SHA256 golang.tar.gz" | sha256sum -c - +tar -C /usr/local -xzf golang.tar.gz +rm golang.tar.gz + +# Build +cd /usr/local/go/src +# see https://golang.org/issue/14851 +patch -p2 -i /app/gogs/build/docker/no-pic.patch +./make.bash + +# Clean +rm /app/gogs/build/docker/*.patch diff --git a/docker/s6/openssh/run b/docker/s6/openssh/run index 99172aab6..9c4c13aca 100755 --- a/docker/s6/openssh/run +++ b/docker/s6/openssh/run @@ -1,7 +1,25 @@ #!/bin/sh -if test -f ./setup; then - source ./setup +# Check if host keys are present, else create them +if ! test -f /data/ssh/ssh_host_rsa_key; then + ssh-keygen -q -f /data/ssh/ssh_host_rsa_key -N '' -t rsa fi +if ! test -f /data/ssh/ssh_host_dsa_key; then + ssh-keygen -q -f /data/ssh/ssh_host_dsa_key -N '' -t dsa +fi + +if ! test -f /data/ssh/ssh_host_ecdsa_key; then + ssh-keygen -q -f /data/ssh/ssh_host_ecdsa_key -N '' -t ecdsa +fi + +if ! test -f /data/ssh/ssh_host_ed25519_key; then + ssh-keygen -q -f /data/ssh/ssh_host_ed25519_key -N '' -t ed25519 +fi + +# Set correct right to ssh keys +chown -R root:root /data/ssh/* +chmod 0700 /data/ssh +chmod 0600 /data/ssh/* + exec gosu root /usr/sbin/sshd -D -f /app/gogs/docker/sshd_config diff --git a/docker/s6/syslogd/run b/docker/s6/syslogd/run index f7bdbe36d..8d929c2e9 100755 --- a/docker/s6/syslogd/run +++ b/docker/s6/syslogd/run @@ -4,4 +4,9 @@ if test -f ./setup; then source ./setup fi -exec gosu root /sbin/syslogd -nS -O- +if [ "$(grep -Ei 'debian' /etc/*release)" ]; then + exec gosu root /sbin/syslogd -nS +else + exec gosu root /sbin/syslogd -nS -O- +fi +