From 2680b16e02f18a08889454573a1468e77c993196 Mon Sep 17 00:00:00 2001 From: Brian Mason Date: Tue, 7 Jan 2020 23:36:13 -0500 Subject: [PATCH] dockerize the corsair app --- .dockerignore | 1 + Dockerfile | 24 ++++++++++++++++++++++++ README.md | 6 ++++++ scripts/run | 23 +++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 scripts/run diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +target/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ea95857 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM rust:1.40.0-alpine as builder + +RUN if [ ! -d /tmp ]; then mkdir /tmp; fi + +WORKDIR /tmp + +COPY Cargo.toml . +COPY Cargo.lock . +COPY src ./src + +RUN cargo build --release + +#------------------------------------------------------------- +FROM alpine:3.11.2 + +RUN apk add --no-cache bash + +COPY --from=builder /tmp/target/release/corsair . + +COPY scripts ./scripts + +# ENV LISTEN_ADDR=127.0.0.1:8000 PROXY_ADDR=127.0.0.1:4000 +CMD ["./scripts/run"] + diff --git a/README.md b/README.md index 0db5633..823ee3b 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,9 @@ CORS-ignoring proxy The `--permissive` flag indicates that all CORS requests should be accepted for proxying. The flag is required for now because I have not yet implemented logic to configure CORS rules. +### run with Docker +``` +docker build -t corsiar . +docker run -it --net=host -e LISTEN_ADDR=127.0.0.1:8080 -e PROXY_ADDR=127.0.0.1:4000 bpmason1/corsair +``` + diff --git a/scripts/run b/scripts/run new file mode 100755 index 0000000..c4a7864 --- /dev/null +++ b/scripts/run @@ -0,0 +1,23 @@ +#! /bin/bash + +set -e + +RED='\033[0;31m' +NC='\033[0m' # No Color + +if [ -z $LISTEN_ADDR ]; then + echo "ERROR - unset environment variable LISTEN_ADDR" + exit 1 +fi + +if [ -z $PROXY_ADDR ]; then + echo "ERROR - unset environment variable PROXY_ADDR" + exit 1 +fi + +SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +ROOT_DIR=$(cd $SCRIPTS_DIR/.. && pwd) + +# this is convenient for running the application in a docker container +./corsair --listen-ip=${LISTEN_ADDR} --proxy-ip=${PROXY_ADDR} --permissive +