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

Slim docker image (around 7 MB) #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ _testmain.go
_cgo_*
_obj
_test

/conf/*.custom
/docker/rootfs/*
17 changes: 3 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
FROM centos:7
FROM scratch
MAINTAINER Misha Nasledov <[email protected]>
MAINTAINER Arnaud de Mouhy <[email protected]>

RUN /usr/bin/yum -y install golang git gcc make mercurial-hgk wget

ENV GOBIN /tmp/bin
ENV GOPATH /tmp

RUN go get github.com/uniqush/uniqush-push

COPY conf/uniqush-push.conf .

RUN cp /tmp/bin/uniqush-push /usr/bin \
&& mkdir /etc/uniqush/ \
&& cp ./uniqush-push.conf /etc/uniqush/ \
&& sed -i -e 's/localhost/0.0.0.0/' /etc/uniqush/uniqush-push.conf
COPY ./docker/rootfs/ /

EXPOSE 9898

Expand Down
10 changes: 10 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:alpine
MAINTAINER Arnaud de Mouhy <[email protected]>

ENV GOBIN /tmp/bin
ENV GOPATH /tmp

RUN apk add --update git

COPY . /tmp/src/github.com/uniqush/uniqush-push
RUN CGO_ENABLED=0 GOOS=linux go get github.com/uniqush/uniqush-push
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ data. Make sure that the Redis server you use has persistence enabled - your
redis.conf should have contents similar to the section `**PERSISTENCE**` of
redis.conf in the example config files linked in http://redis.io/topics/config

## Docker image ##

You can build a [Docker](https://www.docker.com) image with the `scripts/build-docker-image.sh` script.
After building it, you can get a fully working uniqush instance with:

$ docker run -d --name uniqush-redis redis:alpine
$ docker run --publish 9898:9898 --link uniqush-redis:redis --volume /path/to/apns/certificates:/data uniqush-build:$TAG
$ curl http://localhost:9898/version
uniqush-push 2.2.0

## Contributing ##

You're encouraged to contribute to the `uniqush-push` project. There are two ways you can contribute.
Expand Down
24 changes: 24 additions & 0 deletions docker/certificates/GIAG2.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-----BEGIN CERTIFICATE-----
MIID8DCCAtigAwIBAgIDAjqSMA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNVBAYTAlVT
MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i
YWwgQ0EwHhcNMTUwNDAxMDAwMDAwWhcNMTcxMjMxMjM1OTU5WjBJMQswCQYDVQQG
EwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzElMCMGA1UEAxMcR29vZ2xlIEludGVy
bmV0IEF1dGhvcml0eSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
AJwqBHdc2FCROgajguDYUEi8iT/xGXAaiEZ+4I/F8YnOIe5a/mENtzJEiaB0C1NP
VaTOgmKV7utZX8bhBYASxF6UP7xbSDj0U/ck5vuR6RXEz/RTDfRK/J9U3n2+oGtv
h8DQUB8oMANA2ghzUWx//zo8pzcGjr1LEQTrfSTe5vn8MXH7lNVg8y5Kr0LSy+rE
ahqyzFPdFUuLH8gZYR/Nnag+YyuENWllhMgZxUYi+FOVvuOAShDGKuy6lyARxzmZ
EASg8GF6lSWMTlJ14rbtCMoU/M4iarNOz0YDl5cDfsCx3nuvRTPPuj5xt970JSXC
DTWJnZ37DhF5iR43xa+OcmkCAwEAAaOB5zCB5DAfBgNVHSMEGDAWgBTAephojYn7
qwVkDBF9qn1luMrMTjAdBgNVHQ4EFgQUSt0GFhu89mi1dvWBtrtiGrpagS8wDgYD
VR0PAQH/BAQDAgEGMC4GCCsGAQUFBwEBBCIwIDAeBggrBgEFBQcwAYYSaHR0cDov
L2cuc3ltY2QuY29tMBIGA1UdEwEB/wQIMAYBAf8CAQAwNQYDVR0fBC4wLDAqoCig
JoYkaHR0cDovL2cuc3ltY2IuY29tL2NybHMvZ3RnbG9iYWwuY3JsMBcGA1UdIAQQ
MA4wDAYKKwYBBAHWeQIFATANBgkqhkiG9w0BAQsFAAOCAQEACE4Ep4B/EBZDXgKt
10KA9LCO0q6z6xF9kIQYfeeQFftJf6iZBZG7esnWPDcYCZq2x5IgBzUzCeQoY3IN
tOAynIeYxBt2iWfBUFiwE6oTGhsypb7qEZVMSGNJ6ZldIDfM/ippURaVS6neSYLA
EHD0LPPsvCQk0E6spdleHm2SwaesSDWB+eXknGVpzYekQVA/LlelkVESWA6MCaGs
eqQSpSfzmhCXfVUDBvdmWF9fZOGrXW2lOUh1mEwpWjqN0yvKnFUEv/TmFNWArCbt
F4mmk2xcpMy48GaOZON9muIAs0nH5Aqq3VuDx3CQRk6+0NtZlmwu9RY23nHMAcIS
wSHGFg==
-----END CERTIFICATE-----
25 changes: 25 additions & 0 deletions docker/certificates/entrust_2048_ca.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIEKjCCAxKgAwIBAgIEOGPe+DANBgkqhkiG9w0BAQUFADCBtDEUMBIGA1UEChML
RW50cnVzdC5uZXQxQDA+BgNVBAsUN3d3dy5lbnRydXN0Lm5ldC9DUFNfMjA0OCBp
bmNvcnAuIGJ5IHJlZi4gKGxpbWl0cyBsaWFiLikxJTAjBgNVBAsTHChjKSAxOTk5
IEVudHJ1c3QubmV0IExpbWl0ZWQxMzAxBgNVBAMTKkVudHJ1c3QubmV0IENlcnRp
ZmljYXRpb24gQXV0aG9yaXR5ICgyMDQ4KTAeFw05OTEyM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CHG8+c8eS9enNFMFY3h7CI3zJpDC5fcgJCNs2ebb0gIFVbPv/Er
fF6adulZkMV8gzURZVE=
-----END CERTIFICATE-----
46 changes: 46 additions & 0 deletions scripts/build-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

set -eu

TAG=$( git describe --always --dirty )

# Building binary
docker build --tag uniqush-push-builder:$TAG --file Dockerfile.build .

SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
DOCKER_DIR="${SCRIPT_DIR}/../docker"
ROOTFS_DIR="${DOCKER_DIR}/rootfs"
CONFIG_FILE="${SCRIPT_DIR}/../conf/uniqush-push.conf"

mkdir -p "${ROOTFS_DIR}/usr/bin" "${ROOTFS_DIR}/etc/uniqush"

# Copying built binary to host
docker run --rm -v "${ROOTFS_DIR}/usr/bin:/tmp/output" uniqush-push-builder:$TAG cp /tmp/bin/uniqush-push /tmp/output

# Copying conf
if [ -f "${CONFIG_FILE}.custom" ]; then
CONFIG_FILE="${CONFIG_FILE}.custom"
fi
cp "${CONFIG_FILE}" "${ROOTFS_DIR}/etc/uniqush/uniqush-push.conf"

# Copying CA certificates
mkdir -p "${ROOTFS_DIR}/etc/ssl/certs"
cp "${DOCKER_DIR}/certificates/"* "${ROOTFS_DIR}/etc/ssl/certs/"

# Updating conf to be Docker-friendly
sed -i '' \
-e 's!^\(addr\)=.*:\(.*\)$!\1=0.0.0.0:\2!' \
-e 's!/var/log/uniqush$!/dev/stdout!' \
-e $'s!engine=redis!&\\\nhost=redis!' \
"${ROOTFS_DIR}/etc/uniqush/uniqush-push.conf"

# Building slim docker image
docker build --tag uniqush-build:$TAG --file Dockerfile .

docker rmi uniqush-push-builder:$TAG
rm -rf "${ROOTFS_DIR}"

echo
echo ">> Successfully built docker image 'uniqush-build:$TAG'"
echo
docker images uniqush-build:$TAG
5 changes: 4 additions & 1 deletion scripts/run-dockerfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
TAG=$( git describe --always )

function finish {
echo "Removing container..."
docker rm uniqush-push-$TAG
}

trap finish EXIT

docker build --tag uniqush-build:$TAG .
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
bash "${SCRIPT_DIR}/build-docker-image.sh"

docker run \
--name=uniqush-push-$TAG \
uniqush-build:$TAG