diff --git a/Dockerfile b/Dockerfile index b31ba88..5b2142d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,47 +1,19 @@ -FROM ubuntu:16.04 as compy-builder -MAINTAINER Barna Csorogi +FROM golang:1.12-alpine as builder -RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y \ - curl \ - g++ \ - git \ - libjpeg8-dev +WORKDIR /root/go/src/github.com/barnacs/compy/ -RUN mkdir -p /usr/local/ && \ - curl -O https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz && \ - tar xf go1.9.linux-amd64.tar.gz -C /usr/local +COPY . . -RUN mkdir -p /root/go/src/github.com/barnacs/compy/ -COPY . /root/go/src/github.com/barnacs/compy/ -WORKDIR /root/go/src/github.com/barnacs/compy -RUN /usr/local/go/bin/go get -d -v ./... -RUN /usr/local/go/bin/go build -v +RUN apk add --no-cache --no-progress git g++ libjpeg-turbo-dev +RUN go get -d -v ./... +RUN go build -ldflags='-extldflags "-static" -s -w' -o /go/bin/compy -FROM ubuntu:16.04 -MAINTAINER Barna Csorogi -RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y \ - libjpeg8 \ - openssl \ - ssl-cert && \ - DEBIAN_FRONTEND=noninteractive apt-get clean && \ - rm -rf /var/lib/apt/lists/* +FROM scratch -WORKDIR /opt/compy -COPY \ - --from=compy-builder \ - /root/go/src/github.com/barnacs/compy/compy \ - /root/go/src/github.com/barnacs/compy/docker.sh \ - /opt/compy/ +LABEL maintainer="Sandro Jäckel " -# TODO: configure HTTP BASIC authentication -# TODO: user-provided certificates -ENV \ - CERTIFICATE_DOMAIN="localhost" +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /go/bin/compy compy -EXPOSE 9999 -ENTRYPOINT ["./docker.sh"] +ENTRYPOINT ["./compy"] diff --git a/README.md b/README.md index ec13b8e..35ab161 100644 --- a/README.md +++ b/README.md @@ -101,11 +101,19 @@ For compression, transcoding and minification options, see `compy --help` Docker Usage ------------ -Andrew Gaul publishes unofficial Docker images at -https://hub.docker.com/r/andrewgaul/compy/ . You can configure via: - +To build the docker image just run in the git repository ``` -sudo docker run --name=compy --env CERTIFICATE_DOMAIN=example.com --publish 9999:9999 andrewgaul/compy +docker build -t compy . +``` + +To run the container +``` +docker run -d --name compy -p 9999:9999 compy +``` + +To run the container with https enabled. You need to generate the certificates on your host and provide the path to docker. +``` +docker run -d --name compy -p 9999:9999 -v $PWD/cert.crt:/cert.crt -v $PWD/cert.key:/cert.key -v $PWD/ca.crt:/ca.crt -v $PWD/ca.key:/ca.key compy -cert cert.crt -key cert.key -ca ca.crt -cakey ca.key ``` References diff --git a/docker.sh b/docker.sh deleted file mode 100755 index ed2e7ad..0000000 --- a/docker.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -openssl req -x509 -newkey rsa:2048 -nodes -keyout cert.key -out cert.crt -days 3650 -subj "/CN=${CERTIFICATE_DOMAIN}" -openssl req -x509 -newkey rsa:2048 -nodes -keyout ca.key -out ca.crt -days 3650 -subj "/CN=${CERTIFICATE_DOMAIN}" - -echo 'Generated server certificate:' -cat cert.crt -echo -echo 'Generated CA certificate:' -cat ca.crt - -exec ./compy \ - -cert cert.crt -key cert.key \ - -ca ca.crt -cakey ca.key \ - :9999