From 3ce494ababec3c83f30434924f193c097f7e75dd Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Wed, 19 Dec 2018 12:27:58 -0800 Subject: [PATCH] Add gitea dockerfile Change-Id: Iae2c4cbd174212e97445dd3080e2b85be730c5c4 Story: 2004627 --- .zuul.yaml | 80 ++++++++++++++++++ docker/gitea/Dockerfile | 111 +++++++++++++++++++++++++ docker/gitea/sshd-entrypoint.sh | 7 ++ playbooks/zuul/build-image-pre.yaml | 3 + playbooks/zuul/build-image-upload.yaml | 11 +++ playbooks/zuul/build-image.yaml | 7 ++ 6 files changed, 219 insertions(+) create mode 100644 docker/gitea/Dockerfile create mode 100755 docker/gitea/sshd-entrypoint.sh create mode 100644 playbooks/zuul/build-image-pre.yaml create mode 100644 playbooks/zuul/build-image-upload.yaml create mode 100644 playbooks/zuul/build-image.yaml diff --git a/.zuul.yaml b/.zuul.yaml index 11a08e11a6..4329a3f373 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -22,6 +22,81 @@ vars: project_src_dir: "{{ zuul.project.src_dir }}/modules/openstack_project" +# Image building jobs +- secret: + name: system-config-dockerhub + data: + username: openstackzuul + password: !encrypted/pkcs1-oaep + - iz3aVtc1eXwM/d02gaA8qyvryJtrOOTmPZhfWiRw3VaVpuU/lrpSD/qRKPwBEbhFCpzCh + B3eelTaJMKaMsVFU/cD+EOB6MBpCtHreKug3+B1g1Ag9TQaLGfa2d7swPRrhFEENpQBzm + D9OqBYVCWTyGo/Y1nkC/zb+e1H2IdI1axNJrVaKR6FYN8vhpPsflvyW2PCNsdT2YlKCMz + G0wFMJv6zMH6Jw1c0ruHm5pa9O4EWLwhmdxHMeTRAT4JVJdLehVGQLBXvXxZzMOXB2Jrj + KHIMFFhzlc1bZXcFKAMakvfP0ARLmPySEnIcVHjHXvsXmGLuVB0lSXUtUB1QW8qJcso1m + C0ky4VAFHoNB/EV5VGu7btkZDtJKzsQcPXnaT1LcX1xS+QC0bC4SYR25WN9RK7z1sXvMn + dxMIwJIvXOb+aE5mdl63G8OBTxznPAGioCZNjqoMPQJ7VzITSYnPiW5CyZDUinTSDDver + zHBG/Svpwiu7Lm2vOgExHYdCDeo0a5lacxjcwW2FfP7fal3ZLoTeSTGXvIaffS552mZ9L + I0cLfq/ikkbaC4a+bqFnVdDm9wNAyBtOkq5wn3TqOFMrFaBlkI5/34i2fLauZOoka6bcN + zJnvDrjRemvgmWP1q4uI8cPzJK3zjN9/GYrs1MQxHCsNn33sWpc1oHRO+TL/8g= + +- job: + name: system-config-build-image + description: | + Build a docker image. + + .. zuul:jobvar:: images + + A list of images to build. Each item in the list should have: + + .. zuul:jobvar:: context + + The docker build context; should be a directory in this repo. + + .. zuul:jobvar:: target + + Optional; if supplied, the target for a multi-stage build. + + .. zuul:jobvar:: repository + + The name of the target repository in dockerhub for the + image. Supply this even if the image is not going to be + uploaded (it will be tagged with this in the local + registry). + + .. zuul:jobvar:: credentials + + If this is provided, the resulting image will be uploaded. + This should be a secret with two keys: ``username`` and + ``password``. + + abstract: true + pre-run: playbooks/zuul/build-image-pre.yaml + run: playbooks/zuul/build-image.yaml + post-run: playbooks/zuul/build-image-upload.yaml + +- job: + name: system-config-build-image-gitea + description: Build a gitea image + parent: system-config-build-image + vars: + images: + - context: docker/gitea + target: gitea + repository: opendevorg/gitea + - context: docker/gitea + target: gitea-openssh + repository: opendevorg/gitea-openssh + files: + - docker/gitea/.* + +- job: + name: system-config-upload-image-gitea + description: Build and upload a gitea image + parent: system-config-build-image-gitea + secrets: + name: credentials + secret: system-config-dockerhub + # Role integration jobs. These test the top-level generic roles/* # under Zuul. The range of platforms should be the same as those for # openstack-zuul-jobs. @@ -304,6 +379,7 @@ - system-config-run-eavesdrop - system-config-run-nodepool - system-config-run-docker + - system-config-build-image-gitea gate: jobs: - tox-linters @@ -317,3 +393,7 @@ - system-config-run-eavesdrop - system-config-run-nodepool - system-config-run-docker + - system-config-build-image-gitea + post: + jobs: + - system-config-upload-image-gitea diff --git a/docker/gitea/Dockerfile b/docker/gitea/Dockerfile new file mode 100644 index 0000000000..ae0dbb21c2 --- /dev/null +++ b/docker/gitea/Dockerfile @@ -0,0 +1,111 @@ +# Copyright (c) 2018 Red Hat, Inc. +# Copyright (c) 2016 The Gitea Authors +# Copyright (c) 2015 The Gogs Authors +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +################################### +#Build stage +FROM golang:1.11-stretch AS build-env + +LABEL maintainer="infra-root@openstack.org" + +ARG GITEA_VERSION=v1.6.0 +ENV TAGS "bindata $TAGS" + +#Build deps +RUN apt-get update && apt-get -y install build-essential git \ + && mkdir -p ${GOPATH}/src/code.gitea.io/gitea + +#Setup repo +RUN git clone https://github.com/go-gitea/gitea ${GOPATH}/src/code.gitea.io/gitea +WORKDIR ${GOPATH}/src/code.gitea.io/gitea + +#Checkout version if set +RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \ + && make clean generate build + +################################### +# Basic system setup common to all containers in our pod + +FROM debian:testing as base + +RUN apt-get update && apt-get -y install \ + bash \ + ca-certificates \ + curl \ + gettext \ + git \ + openssh-client \ + tzdata \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN addgroup \ + --system --gid 1000 \ + git && \ + adduser \ + --system --no-create-home --disabled-login \ + --home /data/git \ + --shell /bin/bash \ + --uid 1000 \ + --gid 1000 \ + git && \ + echo "git:$(dd if=/dev/urandom bs=24 count=1 status=none | base64)" | chpasswd + +# Copy the /etc config files and entrypoint script +COPY --from=build-env /go/src/code.gitea.io/gitea/docker / + +# Copy the app +COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea +RUN ln -s /app/gitea/gitea /usr/local/bin/gitea + +################################### +# The gitea image +FROM base as gitea + +RUN apt-get update && apt-get -y install pandoc \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +EXPOSE 3000 +ENV USER git +ENV GITEA_CUSTOM /data/gitea +VOLUME ["/data"] +ENTRYPOINT ["/usr/bin/entrypoint"] +CMD ["/app/gitea/gitea"] +USER 1000:1000 + +################################### +# The openssh server image +FROM base as gitea-openssh + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confold" \ + install openssh-server \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ + && mkdir /run/sshd + +COPY sshd-entrypoint.sh /usr/bin/entrypoint + +EXPOSE 22 +VOLUME ["/data"] +ENTRYPOINT ["/usr/bin/entrypoint"] +CMD ["/usr/sbin/sshd", "-D"] diff --git a/docker/gitea/sshd-entrypoint.sh b/docker/gitea/sshd-entrypoint.sh new file mode 100755 index 0000000000..9190b915a5 --- /dev/null +++ b/docker/gitea/sshd-entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e + +# Generate host keys if necessary +/etc/s6/openssh/setup + +exec "$@" diff --git a/playbooks/zuul/build-image-pre.yaml b/playbooks/zuul/build-image-pre.yaml new file mode 100644 index 0000000000..52f5b5b268 --- /dev/null +++ b/playbooks/zuul/build-image-pre.yaml @@ -0,0 +1,3 @@ +- hosts: all + roles: + - install-docker diff --git a/playbooks/zuul/build-image-upload.yaml b/playbooks/zuul/build-image-upload.yaml new file mode 100644 index 0000000000..3e51cacfd6 --- /dev/null +++ b/playbooks/zuul/build-image-upload.yaml @@ -0,0 +1,11 @@ +- hosts: all + tasks: + - name: Upload image to dockerhub + when: credentials is defined + block: + - name: Log in to dockerhub + command: "docker login -u {{ credentials.username }} -p {{ credentials.password }}" + no_log: true + - name: Upload to dockerhub + command: "docker push {{ item.repository }}" + loop: "{{ images }}" \ No newline at end of file diff --git a/playbooks/zuul/build-image.yaml b/playbooks/zuul/build-image.yaml new file mode 100644 index 0000000000..af41c493a5 --- /dev/null +++ b/playbooks/zuul/build-image.yaml @@ -0,0 +1,7 @@ +- hosts: all + tasks: + - name: Build a docker image + command: "docker build . {{ target | default(false) | ternary('--target ', '') }}{{ target | default('') }} --tag {{ item.repository }}" + args: + chdir: "{{ zuul.project.src_dir }}/{{ item.context }}" + loop: "{{ images }}"