diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8f89122 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,126 @@ +FROM alpine:3.6 +MAINTAINER Abner G Jacobsen - http://daspanel.com + +# Thanks: +# https://github.com/openbridge/ob_php-fpm + +# Parse Daspanel common arguments for the build command. +ARG VERSION +ARG VCS_URL +ARG VCS_REF +ARG BUILD_DATE +ARG S6_OVERLAY_VERSION=v1.19.1.1 +ARG DASPANEL_IMG_NAME=svc-api +ARG DASPANEL_OS_VERSION=alpine3.6 + +# Parse Container specific arguments for the build command. +ARG CADDY_PLUGINS="http.cors,http.expires,http.ipfilter,http.ratelimit,http.realip" +ARG CADDY_URL="https://caddyserver.com/download/linux/amd64?plugins=${CADDY_PLUGINS}" +ARG INSTALL_PATH /opt/daspanel/apps/apiserver + +# Set default env variables +ENV \ + # Stop container initialization if error occurs in cont-init.d, fix-attrs.d script's + S6_BEHAVIOUR_IF_STAGE2_FAILS=2 \ + + # Timezone + TZ="UTC" \ + + # DASPANEL defaults + DASPANEL_WAIT_FOR_API="YES" + +# A little bit of metadata management. +# See http://label-schema.org/ +LABEL org.label-schema.schema-version="1.0" \ + org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.version=$VERSION \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.name="daspanel/svc-api" \ + org.label-schema.description="Docker container running Daspanel API server." + +# Inject files in container file system +COPY rootfs / + +RUN set -x \ + + # Initial OS bootstrap - required + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/00_base \ + + # Install Daspanel base - common layer for all container's independent of the OS and init system + && wget -O /tmp/opt-daspanel.zip "https://github.com/daspanel/rootfs-base/releases/download/0.1.0/opt-daspanel.zip" \ + && unzip -o -d / /tmp/opt-daspanel.zip \ + + # Install Daspanel bootstrap for Alpine Linux with S6 Overlay Init system + && wget -O /tmp/alpine-s6.zip "https://github.com/daspanel/rootfs-base/releases/download/0.1.0/alpine-s6.zip" \ + && unzip -o -d / /tmp/alpine-s6.zip \ + + # Bootstrap the system (TBD) + + # Install s6 overlay init system + && wget https://github.com/just-containers/s6-overlay/releases/download/$S6_OVERLAY_VERSION/s6-overlay-amd64.tar.gz --no-check-certificate -O /tmp/s6-overlay.tar.gz \ + && tar xvfz /tmp/s6-overlay.tar.gz -C / \ + && rm -f /tmp/s6-overlay.tar.gz \ + + # ensure www-data user exists + && addgroup -g 82 -S www-data \ + && adduser -u 82 -D -S -h /home/www-data -s /sbin/nologin -G www-data www-data \ + + # Activate additional repositories + && echo '@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories \ + && echo '@community http://nl.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories \ + + # Install build environment packages + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/${DASPANEL_IMG_NAME}/00_buildenv \ + + # Install PHP and modules avaiable on the default repositories of this Linux distro + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/99_install_pkgs "${PHP_MINIMAL}" \ + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/99_install_pkgs "${PHP_MODULES}" \ + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/99_install_pkgs "${PHP_MODULES_EXTRA}" \ + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/99_install_pkgs "${PHP_PHPDBG}" \ + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/99_install_pkgs "${PHP_XDEBUG}" \ + + # Install PHP Composer + && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ + + # Install PHPUnit + && curl -sSL https://phar.phpunit.de/phpunit-6.2.phar -o /usr/local/bin/phpunit \ + && chmod +x /usr/local/bin/phpunit \ + + # PECL fix + # Bug Fix: + # https://serverfault.com/questions/589877/pecl-command-produces-long-list-of-errors + # https://bugs.alpinelinux.org/issues/5378 + # Patch pecl command + && sed -i -e 's/\(PHP -C\) -n/\1/g' /usr/bin/pecl \ + && mkdir -p /tmp/pear/cache \ + + # Cleanup after phpizing + #&& rm -rf /usr/include/php7 /usr/lib/php7/build \ + + # Change www-data user and group to Daspanel default + #&& usermod -u 1000 www-data \ + #&& groupmod -g 1000 www-data \ + + # Remove build environment packages + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/${DASPANEL_IMG_NAME}/09_cleanbuildenv \ + + # Install Caddy + && curl --silent --show-error --fail --location \ + --header "Accept: application/tar+gzip, application/x-gzip, application/octet-stream" -o - \ + "${CADDY_URL}" \ + | tar --no-same-owner -C /usr/sbin/ -xz caddy \ + && chmod 0755 /usr/sbin/caddy \ + && setcap "cap_net_bind_service=+ep" /usr/sbin/caddy \ + + # Cleanup + && rm -rf /tmp/* \ + && rm -rf /var/cache/apk/* + +# Let's S6 control the init system +ENTRYPOINT ["/init"] +CMD [] + +# Expose ports for the service +EXPOSE 443 + diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..fa694b8 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,109 @@ +FROM alpine:3.6 +MAINTAINER Abner G Jacobsen - http://daspanel.com + +# Thanks: +# https://github.com/openbridge/ob_php-fpm + +# Parse Daspanel common arguments for the build command. +ARG VERSION +ARG VCS_URL +ARG VCS_REF +ARG BUILD_DATE +ARG S6_OVERLAY_VERSION=v1.19.1.1 +ARG DASPANEL_IMG_NAME=svc-api +ARG DASPANEL_OS_VERSION=alpine3.6 + +# Parse Container specific arguments for the build command. +ARG CADDY_PLUGINS="http.cors,http.expires,http.ipfilter,http.ratelimit,http.realip" +ARG CADDY_URL="https://caddyserver.com/download/linux/amd64?plugins=${CADDY_PLUGINS}" +ARG INSTALL_PATH=/opt/daspanel/apps/apiserver + +# Set default env variables +ENV \ + # Stop container initialization if error occurs in cont-init.d, fix-attrs.d script's + S6_BEHAVIOUR_IF_STAGE2_FAILS=2 \ + + # Timezone + TZ="UTC" \ + + # DASPANEL defaults + DASPANEL_WAIT_FOR_API="YES" + +# A little bit of metadata management. +# See http://label-schema.org/ +LABEL org.label-schema.schema-version="1.0" \ + org.label-schema.build-date=$BUILD_DATE \ + org.label-schema.version=$VERSION \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.name="daspanel/svc-api" \ + org.label-schema.description="Docker container running Daspanel API server." + +# Inject files in container file system +COPY rootfs / + +RUN set -x \ + + # Initial OS bootstrap - required + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/00_base \ + + # Install Daspanel base - common layer for all container's independent of the OS and init system + && wget -O /tmp/opt-daspanel.zip "https://github.com/daspanel/rootfs-base/releases/download/0.1.0/opt-daspanel.zip" \ + && unzip -o -d / /tmp/opt-daspanel.zip \ + + # Install Daspanel bootstrap for Alpine Linux with S6 Overlay Init system + && wget -O /tmp/alpine-s6.zip "https://github.com/daspanel/rootfs-base/releases/download/0.1.0/alpine-s6.zip" \ + && unzip -o -d / /tmp/alpine-s6.zip \ + + # Bootstrap the system (TBD) + + # Install s6 overlay init system + && wget https://github.com/just-containers/s6-overlay/releases/download/$S6_OVERLAY_VERSION/s6-overlay-amd64.tar.gz --no-check-certificate -O /tmp/s6-overlay.tar.gz \ + && tar xvfz /tmp/s6-overlay.tar.gz -C / \ + && rm -f /tmp/s6-overlay.tar.gz \ + + # Install Python + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/${DASPANEL_IMG_NAME}/10_install_python2.7 \ + + # Install build environment packages + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/${DASPANEL_IMG_NAME}/00_buildenv \ + + # Install pyCurl + && export PYCURL_SSL_LIBRARY=openssl \ + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/${DASPANEL_IMG_NAME}/20_pip2.7_install "--compile pycurl==7.43.0" \ + + # Install basic python packages used by Daspanel + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/${DASPANEL_IMG_NAME}/20_pip2.7_install "gunicorn==19.7.1 setproctitle gevent" \ + + # Install software + && mkdir -p ${INSTALL_PATH} \ + && wget --no-check-certificate -O /tmp/api-src.zip https://github.com/daspanel/api-server/archive/master.zip \ + && unzip -o -d /tmp /tmp/api-src.zip \ + && mv /tmp/api-server-master/api_server ${INSTALL_PATH}/. \ + && mv /tmp/api-server-master/requirements ${INSTALL_PATH}/. \ + + # Install pip packages needed by the software + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/${DASPANEL_IMG_NAME}/20_pip2.7_install "-r ${INSTALL_PATH}/requirements/prod.txt " \ + + # Remove build environment packages + && sh /opt/daspanel/bootstrap/${DASPANEL_OS_VERSION}/${DASPANEL_IMG_NAME}/09_cleanbuildenv \ + + # Install Caddy + #&& curl --silent --show-error --fail --location \ + # --header "Accept: application/tar+gzip, application/x-gzip, application/octet-stream" -o - \ + # "${CADDY_URL}" \ + # | tar --no-same-owner -C /usr/sbin/ -xz caddy \ + #&& chmod 0755 /usr/sbin/caddy \ + #&& setcap "cap_net_bind_service=+ep" /usr/sbin/caddy \ + + # Cleanup + && rm -rf /tmp/* \ + && rm -rf /var/cache/apk/* + +# Let's S6 control the init system +ENTRYPOINT ["/init"] +CMD [] + +# Expose ports for the service +EXPOSE 8080 + diff --git a/Makefile b/Makefile index 1329e8d..6053dc3 100644 --- a/Makefile +++ b/Makefile @@ -65,10 +65,10 @@ docker-clean-dangling: docker images --no-trunc -q -f dangling=true | xargs -r docker rmi docker-clean-dev: - -@docker rmi admindaspanel/svc-api-dev + -@docker rmi daspanel/svc-api-dev docker-build-dev: clean docker-clean-dev rootfs-fixperms - docker build -f Dockerfile.dev -t admindaspanel/svc-api-dev . + docker build -f Dockerfile.dev -t daspanel/svc-api-dev . install-tools: sudo pip install gitchangelog pystache diff --git a/daspanel.env b/daspanel.env new file mode 100644 index 0000000..2328fba --- /dev/null +++ b/daspanel.env @@ -0,0 +1,2 @@ +DASPANEL_SYS_UUID=civmw76wg000001p2dwqxpvet + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..29c64cc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '2' +services: + daspanel-api: + image: daspanel/svc-api-dev + volumes: + - ./data:/opt/daspanel/data + networks: + - frontend + - backend + environment: + - LOCAL_USER_ID=1000 + - GUNICORN_APP_DIR=/opt/daspanel/apps/apiserver/api_server + - GUNICORN_CMD=/opt/daspanel/apps/apiserver/api_server/wsgi_gunicorn --bind=0.0.0.0:8080 --user=daspanel --group=daspanel api-connexion:app Daspanel_Api_Server + - DASPANEL_WAIT_FOR_API=NO + env_file: + - daspanel.env + expose: + - "8080" +networks: + frontend: + driver: bridge + backend: + driver: bridge + + diff --git a/src/.gitkeep b/rootfs/.gitkeep similarity index 100% rename from src/.gitkeep rename to rootfs/.gitkeep diff --git a/rootfs/opt/.gitkeep b/rootfs/opt/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/opt/daspanel/.gitkeep b/rootfs/opt/daspanel/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/opt/daspanel/bootstrap/alpine3.6/00_base b/rootfs/opt/daspanel/bootstrap/alpine3.6/00_base new file mode 100755 index 0000000..a9d0dd8 --- /dev/null +++ b/rootfs/opt/daspanel/bootstrap/alpine3.6/00_base @@ -0,0 +1,12 @@ +#!/bin/sh + +set -x + +# Install minimal packages +apk add --update --no-cache ca-certificates wget tzdata unzip 'su-exec>=0.2' \ + libcap mailcap ssmtp curl tar bash + +# Create folder is in $PATH by default but isn't created by default +mkdir -p /usr/local/sbin + +mkdir -p /var/run diff --git a/rootfs/opt/daspanel/bootstrap/alpine3.6/99_install_pkgs b/rootfs/opt/daspanel/bootstrap/alpine3.6/99_install_pkgs new file mode 100755 index 0000000..71b3101 --- /dev/null +++ b/rootfs/opt/daspanel/bootstrap/alpine3.6/99_install_pkgs @@ -0,0 +1,9 @@ +#!/bin/sh + +PKGS=$1 + +set -x + +# Install Distro packages +apk add --no-cache --update $PKGS + diff --git a/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/.gitkeep b/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/00_buildenv b/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/00_buildenv new file mode 100755 index 0000000..83c68ef --- /dev/null +++ b/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/00_buildenv @@ -0,0 +1,10 @@ +#!/bin/sh + +set -x + +# Install build packages +apk add --no-cache --update --virtual build-deps \ + build-base \ + build-base bash gcc musl-dev git libressl-dev curl curl-dev python-dev \ + libffi-dev mariadb-dev python-dev libxml2-dev libxslt-dev + diff --git a/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/09_cleanbuildenv b/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/09_cleanbuildenv new file mode 100755 index 0000000..1dedba1 --- /dev/null +++ b/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/09_cleanbuildenv @@ -0,0 +1,8 @@ +#!/bin/sh + +set -x + +# Remove build packages +apk del --purge build-deps + + diff --git a/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/10_install_python2.7 b/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/10_install_python2.7 new file mode 100755 index 0000000..9b84554 --- /dev/null +++ b/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/10_install_python2.7 @@ -0,0 +1,14 @@ +#!/bin/sh + +set -x + +# Install Python 2.7 +apk add --no-cache --update libssl1.0 libcurl python2 +python -m ensurepip +rm -r /usr/lib/python*/ensurepip + +# Install pip +curl "https://bootstrap.pypa.io/get-pip.py" | python +pip install --no-cache-dir --upgrade pip setuptools +rm -r /root/.cache + diff --git a/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/20_pip2.7_install b/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/20_pip2.7_install new file mode 100755 index 0000000..9bbd491 --- /dev/null +++ b/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/20_pip2.7_install @@ -0,0 +1,9 @@ +#!/bin/sh + +MODULE=$1 + +set -x + +# Install Distro packages +yes '' | pip install --no-cache-dir --upgrade $MODULE + diff --git a/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/20_pip_install b/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/20_pip_install new file mode 100644 index 0000000..8dcc831 --- /dev/null +++ b/rootfs/opt/daspanel/bootstrap/alpine3.6/svc-api/20_pip_install @@ -0,0 +1,9 @@ +#!/bin/sh + +MODULE=$1 + +set -x + +# Install python packages +yes '' | pip install --no-cache-dir --upgrade $MODULE +rm -r /root/.cache