diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..4d8bdfc --- /dev/null +++ b/.drone.yml @@ -0,0 +1,58 @@ +kind: pipeline +type: docker +name: build-amd64 +platform: + arch: amd64 +steps: + - name: push + image: plugins/docker + when: + branch: + - main + settings: + dockerfile: Dockerfile + repo: git.jacknet.io/jackhadrill/container-director + tags: amd64 + username: jackhadrill + password: + from_secret: password + registry: git.jacknet.io +--- +kind: pipeline +type: docker +name: build-arm64 +platform: + arch: arm64 +steps: + - name: push + image: plugins/docker + when: + branch: + - main + settings: + dockerfile: Dockerfile + repo: git.jacknet.io/jackhadrill/container-director + tags: arm64 + username: jackhadrill + password: + from_secret: password + registry: git.jacknet.io +--- +kind: pipeline +type: docker +name: manifest +depends_on: + - build-amd64 + - build-arm64 +steps: + - name: manifest + image: plugins/manifest + settings: + username: JackNet + password: + from_secret: password + target: git.jacknet.io/jackhadrill/container-director:latest + template: git.jacknet.io/jackhadrill/container-director:ARCH + platforms: + - linux/amd64 + - linux/arm64 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bfd1c64 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM nginx:alpine + +ENV LISTEN_PORT="80" +ENV CONTAINER_PREFIX="container" +ENV SPAWNER_HOST="spawner" +ENV SPANWER_PORT="80" + +COPY director.conf /etc/nginx/templates/director.conf.template diff --git a/README.md b/README.md index 1f07412..0d1aeb1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,22 @@ -# code-spawner +# Container Director +[![Build Status](https://drone.jacknet.io/api/badges/jackhadrill/container-director/status.svg)](https://drone.jacknet.io/jackhadrill/container-director) + +A tool to proxy an HTTP backend, and failover to a "container spawner" if the backend does not exist. + +## Usage + +```yml +version: '3' +services: + ... + container-director: + image: git.jacknet.io/jackhadrill/container-director:latest + restart: always + environment: + LISTEN_PORT: 80 + CONTAINER_PREFIX: "container" + SPAWNER_HOST: "spawner" + SPANWER_PORT: 80 + ... +``` diff --git a/director.conf b/director.conf new file mode 100644 index 0000000..967053d --- /dev/null +++ b/director.conf @@ -0,0 +1,15 @@ +server { + listen ${LISTEN_PORT}; + server_name _; + + resolver 127.0.0.11 valid=1s; + + location / { + proxy_pass http://${CONTAINER_PREFIX}$http_x_forwarded_preferred_username$uri; + error_page 502 = @spawner; + } + + location @spawner { + proxy_pass http://${SPAWNER_HOST}:${SPANWER_PORT}$uri; + } +}