Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.2.0 #24

Merged
merged 45 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
dd6fe17
User /etc/supervisord.conf directly
lmakarov Aug 8, 2017
b1ed7f8
Added timestamp in logs from proxyctl
lmakarov Aug 8, 2017
8b9eead
supervisord.conf adjustments
lmakarov Aug 8, 2017
b16de18
Removing legacy "OS: linux" from .travis.yml
lmakarov Aug 16, 2017
af32e8f
Increase proxy buffers https://stackoverflow.com/a/13896157/1359178
Dec 18, 2017
54a9c70
Merge pull request #19 from docksal/proxy-buffers
lmakarov Dec 18, 2017
8a418bd
Use ARG instead of ENV for versions
lmakarov Dec 22, 2017
2784d19
PROXY_ACCESS_LOG variable
lmakarov Dec 22, 2017
4806cb5
Get rid of /usr/bin/ in proxyctl
lmakarov Dec 22, 2017
a2b0bea
Reduce crond log verbosity to default
lmakarov Dec 22, 2017
d123164
Added projects stats in logs
lmakarov Dec 22, 2017
5a36e85
Refactoring
lmakarov Dec 22, 2017
529b155
Replaces spaces with tabs in smoke-test.bats
lmakarov Dec 22, 2017
fecfc51
Fix typo
lmakarov Dec 22, 2017
4a16217
Added aggregated stats for projects
lmakarov Dec 27, 2017
94e2947
Run cron every minute
lmakarov Dec 27, 2017
da1d928
Switched to boolean values in stats
lmakarov Dec 27, 2017
d8fdf26
Adjust cron schedule
lmakarov Jan 5, 2018
ecffdba
Switch to dev version of Docksal
lmakarov Jan 17, 2018
8428f9c
Fix "simple variable usage" warning in PHPStorm
lmakarov Jan 17, 2018
2297d4f
Removed the dependency on "web" (docksal/docksal#427)
lmakarov Jan 17, 2018
f6a3eca
Updated logging configuration variables
lmakarov Feb 4, 2018
45e168f
Adjust default.conf.tmpl template
lmakarov Feb 4, 2018
ffe5392
Virtual port configuration via io.docksal.virtual-port label
lmakarov Feb 4, 2018
ae19312
Give configs and template more meaningful names
lmakarov Feb 4, 2018
d15ba87
Updating tests
lmakarov Feb 5, 2018
7f3b093
Big refactoring
lmakarov Feb 6, 2018
39e1fff
fin: feature/docksal-projects-volume
lmakarov Feb 6, 2018
93aa45a
Test case: Projects directory mounted correctly
lmakarov Feb 6, 2018
22e5a63
Enabled logging and increase wait time in tests
lmakarov Feb 6, 2018
69eabc7
Switch back to docksal/develop
lmakarov Feb 6, 2018
46abdcc
HTTP/2 support. Fixes #17
lmakarov Mar 6, 2018
fc72be6
Minor tests update
lmakarov Mar 6, 2018
5f8ecf1
Fixing HTTP/2 tests (#17)
lmakarov Mar 8, 2018
c462abf
Added .gitignore
lmakarov Mar 8, 2018
d17ec71
proxyctl updates
lmakarov Mar 8, 2018
9af1e64
Multiple fixes in tests
lmakarov Mar 8, 2018
ab67c90
Using protocol-relative URLs in loading and not-found screens
lmakarov Mar 8, 2018
ba3adfa
Updated README
lmakarov Mar 8, 2018
7ff0e46
Extended make cleanup
lmakarov Mar 8, 2018
7d506bd
Added virtual-port tests
lmakarov Mar 8, 2018
4fb36b6
Fix tests
lmakarov Mar 9, 2018
3c6f174
Pushing images to Docker Hub via Travis
lmakarov Mar 12, 2018
7db7fc6
README updates
lmakarov Mar 15, 2018
360c6b3
Version updates
lmakarov Mar 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
projects
42 changes: 35 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ sudo: required
language: generic

env:
OS: linux
IMAGE_NAME: vhost-proxy:test
REPO: docksal/vhost-proxy
IMAGE_VHOST_PROXY: ${REPO}:dev
DOCKSAL_VHOST_PROXY_ACCESS_LOG: 1
DOCKSAL_VHOST_PROXY_DEBUG_LOG: 1
DOCKSAL_VHOST_PROXY_STATS_LOG: 1
# Only use seconds here, so that these can be used with "sleep" as well
PROJECT_INACTIVITY_TIMEOUT: 30s
PROJECT_DANGLING_TIMEOUT: 60s
PROXY_DEBUG: 1
DOCKSAL_VERSION: master
PROJECTS_ROOT: ${TRAVIS_BUILD_DIR}/projects
DOCKSAL_VERSION: develop

services:
- docker
Expand All @@ -18,12 +21,37 @@ install:
- sudo sudo curl -L https://raw.githubusercontent.com/docksal/docksal/${DOCKSAL_VERSION}/bin/fin -o /usr/local/bin/fin && sudo chmod +x /usr/local/bin/fin
- fin version
- fin update
- fin docker build -t ${IMAGE_NAME} .
- PROJECTS_ROOT=$TRAVIS_BUILD_DIR IMAGE_VHOST_PROXY=$IMAGE_NAME fin reset proxy
- fin sysinfo

before_script:
# Pull curl image with http2 support (used in tests)
- docker pull badouralix/curl-http2
- .travis/before_script.sh
- ls -la "$PROJECTS_ROOT"
- fin pl -a

script:
- bats tests/smoke-test.bats
- make
- make start
- make exec -e CMD="env" # Views env variables picked up by proxy
- make exec -e CMD="ls -la /projects" # View the contents of the /projects folder
- make test

after_success: |
if [[ "${TRAVIS_PULL_REQUEST}" == "false" ]]; then
# develop => edge
[[ "${TRAVIS_BRANCH}" == "develop" ]] && TAG="edge"
# master => latest
[[ "${TRAVIS_BRANCH}" == "master" ]] && TAG="latest"
# tags/v1.2.0 => 1.2
[[ "${TRAVIS_TAG}" != "" ]] && TAG="${TRAVIS_TAG:1:3}"

if [[ "$TAG" != "" ]]; then
docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"
docker tag ${IMAGE_VHOST_PROXY} ${REPO}:${TAG}
docker push ${REPO}:${TAG}
fi
fi

after_failure:
- make logs
56 changes: 45 additions & 11 deletions .travis/before_script.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
#!/usr/bin/env bash

# Store build directory
cwd=$(pwd)

rm -rf ${cwd}/projects
mkdir -p ${cwd}/projects/project1
mkdir -p ${cwd}/projects/project2
mkdir -p ${cwd}/projects/project3

# Regular project
git clone https://github.com/docksal/drupal7.git ../drupal7
cwd=$(pwd) && cd ../drupal7
fin start
cd $cwd

# Project with the "io.docksal.permanent" flag set to true
# This project will not be automatically cleaned even after DANGLING_TIMEOUT period.
git clone https://github.com/docksal/drupal8.git ../drupal8
cwd=$(pwd) && cd ../drupal8
cd ${cwd}/projects/project1
mkdir .docksal && mkdir docroot
echo "Hello world: Project 1" > docroot/index.html
fin reset -f

# Permanent project
# "io.docksal.permanent=true" (will not be automatically cleaned even after DANGLING_TIMEOUT period)
cd ${cwd}/projects/project2
mkdir .docksal && mkdir docroot
echo "Hello world: Project 2" > docroot/index.html
local_yml="
version: '2.1'

Expand All @@ -19,6 +28,31 @@ services:
- io.docksal.permanent=true
"
echo "$local_yml" > .docksal/docksal-local.yml
fin reset -f

# Nodejs app project
# "io.docksal.virtual-port=3000" (proxy forwards HTTP requests to a custom port 3000 instead of the default 80)
cd ${cwd}/projects/project3
git clone https://github.com/docksal/example-nodejs.git .
# Make this project permanent too, otherwise it will be killed before tests run
local_yml="
version: '2.1'

services:
cli:
labels:
- io.docksal.permanent=true
"
echo "$local_yml" > .docksal/docksal-local.yml
fin reset -f

fin start
cd $cwd
# Nodejs app (standalone container)
# Node need to make this one permanent ("io.docksal.permanent=true") since it is a standalone container and not a project
fin docker rm -vf nodejs || true
fin docker run -d --name=nodejs \
-v $(pwd):/app \
--label=io.docksal.virtual-host=nodejs.docksal \
--label=io.docksal.virtual-port=3000 \
--expose 3000 \
node:alpine \
node /app/index.js
44 changes: 28 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ RUN apk add --no-cache \
nginx-lua \
&& rm -rf /var/cache/apk/*

ENV DOCKER_VERSION 17.06.0-ce
ENV DOCKER_GEN_VERSION 0.7.3
ARG DOCKER_VERSION=17.09.1-ce
ARG DOCKER_GEN_VERSION=0.7.4
ARG GOTPL_VERSION=0.1.5

# Install docker client binary from Github (if not mounting binary from host)
RUN curl -sSL -O "https://download.docker.com/linux/static/stable/x86_64/docker-$DOCKER_VERSION.tgz" \
# Install docker client binary (if not mounting binary from host)
RUN curl -sSL -O "https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz" \
&& tar zxf docker-$DOCKER_VERSION.tgz && mv docker/docker /usr/local/bin && rm -rf docker-$DOCKER_VERSION*

# Install docker-gen
ENV DOCKER_GEN_TARFILE docker-gen-alpine-linux-amd64-$DOCKER_GEN_VERSION.tar.gz
RUN curl -sSL https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/$DOCKER_GEN_TARFILE -O \
ARG DOCKER_GEN_TARFILE=docker-gen-alpine-linux-amd64-$DOCKER_GEN_VERSION.tar.gz
RUN curl -sSL -O "https://github.com/jwilder/docker-gen/releases/download/${DOCKER_GEN_VERSION}/${DOCKER_GEN_TARFILE}" \
&& tar -C /usr/local/bin -xvzf $DOCKER_GEN_TARFILE && rm $DOCKER_GEN_TARFILE

# Install gotpl
ARG GOTPL_TARFILE=gotpl-alpine-linux-amd64-${GOTPL_VERSION}.tar.gz
RUN curl -sSL -O "https://github.com/wodby/gotpl/releases/download/${GOTPL_VERSION}/${GOTPL_TARFILE}" \
&& tar -C /usr/local/bin -xvzf $GOTPL_TARFILE && rm $GOTPL_TARFILE

RUN chown -R nginx:nginx /var/lib/nginx

# Generate a self-signed cert
Expand All @@ -29,24 +35,30 @@ RUN apk add --no-cache openssl \
-keyout /etc/nginx/server.key -out /etc/nginx/server.crt \
&& apk del openssl

COPY conf/nginx/nginx.conf /etc/nginx/nginx.conf
COPY conf/nginx/default.conf.tmpl /etc/nginx/default.conf.tmpl
COPY conf/nginx/default_locations.conf /etc/nginx/default_locations.conf
COPY conf/nginx /opt/conf/nginx
COPY conf/sudoers /etc/sudoers
COPY conf/supervisord.conf /etc/supervisor.d/supervisord.ini
# Override the main supervisord config file, since some parameters are not overridable via an include
# See https://github.com/Supervisor/supervisor/issues/962
COPY conf/supervisord.conf /etc/supervisord.conf
COPY conf/crontab /var/spool/cron/crontabs/root
COPY bin /usr/local/bin
COPY www /var/www/proxy

# Fix permissions
RUN chmod 0440 /etc/sudoers

# Disable INACTIVITY_TIMEOUT by default
ENV PROJECT_INACTIVITY_TIMEOUT 0
# Disable DANGLING_TIMEOUT by default
ENV PROJECT_DANGLING_TIMEOUT 0
# Disable debug output by default
ENV PROXY_DEBUG 0

ENV \
# Disable INACTIVITY_TIMEOUT by default
PROJECT_INACTIVITY_TIMEOUT=0 \
# Disable DANGLING_TIMEOUT by default
PROJECT_DANGLING_TIMEOUT=0 \
# Disable access log by default
ACCESS_LOG=0 \
# Disable debug output by default
DEBUG_LOG=0 \
# Disable stats log by default
STATS_LOG=0

ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
50 changes: 50 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-include env_make

VERSION ?= dev

REPO = docksal/vhost-proxy
NAME = docksal-vhost-proxy

.PHONY: build test push shell run start stop logs debug clean release

build:
fin docker build -t $(REPO):$(VERSION) .

test:
IMAGE=$(REPO):$(VERSION) bats tests/smoke-test.bats

push:
fin docker push $(REPO):$(VERSION)

exec:
fin docker exec -it $(NAME) $(CMD)

shell:
make exec -e CMD=bash

start:
fin system reset vhost-proxy

stop:
fin docker stop $(NAME)

logs:
fin docker logs $(NAME)

clean:
fin docker rm -f $(NAME)
rm -rf projects
fin cleanup

debug: build start
fin docker logs -f $(NAME)

release: build
make push -e VERSION=$(VERSION)

# Curl command with http2 support via a docker container
# Usage: make curl -e ARGS='-kI https://docksal.io'
curl:
docker run -t --rm badouralix/curl-http2 $(ARGS)

default: build
63 changes: 53 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,50 @@ This image(s) is part of the [Docksal](http://docksal.io) image library.

Start the proxy container:

```
```bash
docker run -d --name docksal-vhost-proxy --label "io.docksal.group=system" --restart=always --privileged --userns=host \
-p "${DOCKSAL_VHOST_PROXY_PORT_HTTP:-80}":80 -p "${DOCKSAL_VHOST_PROXY_PORT_HTTPS:-443}":443 \
-e PROJECT_INACTIVITY_TIMEOUT="${PROJECT_INACTIVITY_TIMEOUT:-0}" \
-v /var/run/docker.sock:/var/run/docker.sock \
docksal/vhost-proxy
```

## Configuration
## Container configuration

Proxy reads routing settings from container labels. The following labels are supported:

`io.docksal.virtual-host`

Virtual host mapping. Supports any domain (but does not handle DNS), multiple values separated by commas, wildcard
sub-domains.

Example: `io.docksal.virtual-host=example1.com,*.example2.com`


`io.docksal.virtual-port`

Virtual port mapping. Useful when a container exposes an non-default HTTP port (other than port `80`).
Only supports HTTP, single value.

Example: `io.docksal.virtual-port=3000`

### Example

Launching a nodejs app container using port `3000` and host `myapp.example.com`

```bash
docker run -d --name=nodejs \
-v $(pwd):/app \
--label=io.docksal.virtual-host=myapp.example.com \
--label=io.docksal.virtual-port=3000 \
--expose 3000 \
node:alpine \
node /app/index.js
```

## Advanced proxy configuration

These advanced settings can be used in CI sandbox environments and help keep the resource usage down by stopping
Docksal project containers after a period of inactivity. Projects are automatically restarting upon a new HTTP request.

`PROJECT_INACTIVITY_TIMEOUT`

Expand All @@ -32,34 +67,42 @@ This option is inactive by default (set to `0`).

`PROJECT_DANGLING_TIMEOUT`

!!!warning "WARNING"
This is a destructive option. Use at your own risk!
**WARNING: This is a destructive option. Use at your own risk!**

Defines the timeout (e.g. 168h) of inactivity after which the project stack and code base will be entirely wiped out from the host.
This option is inactive by default (set to `0`).

For the cleanup job to work, proxy needs access to the directory, where project code bases are located on the host.
For the cleanup job to work, proxy needs access to the projects directory on the host.
Create a Docker bind volume pointing to the directory where projects are stored:

```
docker volume create --name docksal_projects --opt type=none --opt device=$PROJECTS_ROOT --opt o=bind

```

Start the proxy container with two additional options (in the middle):
then pass it using `-v docksal_projects:/projects` in `docker run` command.

```
Example (extra configuration in the middle):

```bash
docker run -d --name docksal-vhost-proxy --label "io.docksal.group=system" --restart=always --privileged --userns=host \
-p "${DOCKSAL_VHOST_PROXY_PORT_HTTP:-80}":80 -p "${DOCKSAL_VHOST_PROXY_PORT_HTTPS:-443}":443 \
-e PROJECT_INACTIVITY_TIMEOUT="${PROJECT_INACTIVITY_TIMEOUT:-0}" \

-e PROJECT_INACTIVITY_TIMEOUT="${PROJECT_INACTIVITY_TIMEOUT:-0}" \
-e PROJECT_DANGLING_TIMEOUT="${PROJECT_DANGLING_TIMEOUT:-0}" \
-v docksal_projects:/projects \

-v /var/run/docker.sock:/var/run/docker.sock \
docksal/vhost-proxy
```

`PROXY_DEBUG`
## Logging and debugging

The following container environment variables can be used to enabled various logging options (disabled by default).

`ACCESS_LOG` - Set to `1` to enable access logging.
`DEBUG_LOG` - Set to `1` to enable debug logging.
`STATS_LOG` - Set to `1` to enable project stats logging.

Set to `1` to enable debug logging. Check logs with `docker logs docksal-vhost-proxy`.
Check logs with `docker logs docksal-vhost-proxy`.
4 changes: 4 additions & 0 deletions bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

# Service mode (run as root)
if [[ "$1" == "supervisord" ]]; then
# Generate config files from templates
gotpl /opt/conf/nginx/nginx.conf.tmpl > /etc/nginx/nginx.conf
gotpl /opt/conf/nginx/proxyctl.conf.tmpl > /etc/nginx/proxyctl.conf

exec supervisord -c /etc/supervisord.conf
# Command mode (run as docker user)
else
Expand Down
Loading