Skip to content

Commit

Permalink
Docker debian -> ubuntu. use multi stage build
Browse files Browse the repository at this point in the history
  • Loading branch information
aldor007 committed Dec 2, 2017
1 parent 8c8d25b commit e485f32
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 62 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
src/*
vendor/*
pkg/*
node_modules/*
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ script:
- cd -
- sudo curl -fsSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/v0.3.2/dep-linux-amd64 && sudo chmod +x /usr/local/bin/dep
- dep ensure -vendor-only
- make unit
- make unit


94 changes: 46 additions & 48 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,78 +1,76 @@
# Start from a Debian image with the latest version of Go installed
# and a workspace (GOPATH) configured at /go.
FROM golang:1.9.2-stretch as builder
FROM ubuntu:16.04 as builder


ENV LIBVIPS_VERSION 8.5.9
ENV DEP_VERSION v0.3.2
ENV GOLANG_VERSION 1.9.2


# Installs libvips + required libraries
RUN \
# Install dependencies
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
automake build-essential curl \
gobject-introspection gtk-doc-tools libglib2.0-dev libjpeg-dev libpng-dev \
libwebp-dev libtiff5-dev libgif-dev libexif-dev libxml2-dev libpoppler-glib-dev \
swig libmagickwand-dev libpango1.0-dev libmatio-dev libopenslide-dev libcfitsio-dev \
libgsf-1-dev fftw3-dev liborc-0.4-dev librsvg2-dev && \
# Build libvips
cd /tmp && \
curl -OL https://github.com/jcupitt/libvips/releases/download/v${LIBVIPS_VERSION}/vips-${LIBVIPS_VERSION}.tar.gz && \
tar zvxf vips-${LIBVIPS_VERSION}.tar.gz && \
cd /tmp/vips-${LIBVIPS_VERSION} && \
./configure --enable-debug=no --without-python $1 && \
make && \
make install && \
ldconfig && \
# Clean up
apt-get remove -y curl automake build-essential && \
apt-get autoremove -y && \
apt-get autoclean && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Server port to listen
ENV PORT 8080
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
automake build-essential curl \
gobject-introspection gtk-doc-tools libglib2.0-dev libjpeg-turbo8-dev libpng12-dev \
libwebp-dev libtiff5-dev libgif-dev libexif-dev libxml2-dev libpoppler-glib-dev \
swig libmagickwand-dev libpango1.0-dev libmatio-dev libopenslide-dev libcfitsio-dev \
libgsf-1-dev fftw3-dev liborc-0.4-dev librsvg2-dev && \
cd /tmp && \
curl -OL https://github.com/jcupitt/libvips/releases/download/v${LIBVIPS_VERSION}/vips-${LIBVIPS_VERSION}.tar.gz && \
tar zvxf vips-${LIBVIPS_VERSION}.tar.gz && \
cd /tmp/vips-${LIBVIPS_VERSION} && \
./configure --enable-debug=no --without-python $1 && \
make && \
make install && \
ldconfig && \
apt-get remove -y curl automake build-essential && \
apt-get autoremove -y && \
apt-get autoclean && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# gcc for cgo
RUN apt-get update && apt-get install -y \
gcc curl git libc6-dev make ca-certificates \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz

RUN curl -fsSL --insecure "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \
&& tar -C /usr/local -xzf golang.tar.gz \
&& rm golang.tar.gz

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
# ENV GOROOT /go:$GOROOT

RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
WORKDIR $GOPATH
RUN curl -fsSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/$DEP_VERSION/dep-linux-amd64 && chmod +x /usr/local/bin/dep
ADD . /go/src/github.com/aldor007/mort

RUN cd /go/src/github.com/aldor007/mort && dep ensure -vendor-only
# RUN build
RUN cd /go; go build -o /go/mort src/github.com/aldor007cmd/mort/mort.go; cp -r /go/src/github.com/aldor007/mort/configuration /go/
RUN cd /go/src/github.com/aldor007/mort; go build -o /go/mort cmd/mort/mort.go; cp -r /go/src/github.com/aldor007/mort/configuration /go/

# clean up
RUN rm -rf /go/src; rm -rf /go/pkg; rm -rf /usr/share/; rm -rf /usr/include/


#FROM golang:1.9.2-stretch

FROM debian:stretch
FROM ubuntu:16.04

RUN \
# Install dependencies
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
libglib2.0 libjpeg libpng \
libwebpv libtiff5 libgifv libexifv libxml2 libpoppler-glib \
libmagickwand libpango1.0 libmatio libopenslidev libcfitsio \
libgsf-1 fftw3 liborc-0.4 librsvg2 && \
# Clean up
apt-get remove -y curl automake build-essential && \
apt-get autoremove -y && \
apt-get autoclean && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Install runtime dependencies
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
libglib2.0-0 libjpeg-turbo8 libpng12-0 libopenexr22 \
libwebp5 libtiff5 libgif7 libexif12 libxml2 libpoppler-glib8 \
libmagickwand-6.q16-2 libpango1.0-0 libmatio2 libopenslide0 \
libgsf-1-114 fftw3 liborc-0.4 librsvg2-2 libcfitsio2 && \
# Clean up
apt-get autoremove -y && \
apt-get autoclean && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# clean up
RUN rm -rf /go/src; rm -rf /usr/share/; rm -rf /usr/include/
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ install:
unit:
@(go list ./... | grep -v "vendor/" | xargs -n1 go test -v -cover)

coverage:
go test github.com/aldor007/mort/... -race -coverprofile=coverage.txt -covermode=atomic

integrations:
npm install
./scripts/run-tests.sh
Expand Down
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ $ ./mort
Usage of mort
-config string
Path to configuration (default "configuration/config.yml")
-listen string
Listen addr (default ":8080")
```

## Configuration
Expand Down Expand Up @@ -183,32 +181,43 @@ More details about configuration can be found in [Configuration.md](doc/Configur
I will provide Debian package when we will be completely stable ;)

## Docker
See [Dockerfile](Dockerfile) for image details.

Pull docker image

```bash
docker pull aldor007/mort

```

Create Dockerfile
### Create you custom docker deployment

Create Dockerfile or use Dockerfile.service
```
FROM aldor007/mort:latest
ADD config.yml /go/configuration/config.yml # add yours config
```

Run docker
Build container
```bash
docker build -f Dockerfile.service -t myusername/mort
```

Run docker
```
docker run -p 8080:8080 myusername/mort
```

# Development
1. Make sure you have a Go language compiler >= 1.9 (required) and git installed.
2. Install libvips like described on [bimg page](https://github.com/h2non/bimg)
3. Ensure your GOPATH is properly set.
4. Download it
```bash
go get -d github.com/aldor007/mort
git clone https://github.com/aldor007/mort.git $GOPATH/src/github.com/aldor007/mort
cd $GOPATH/src/github.com/aldor007/mort
```
5, Install dependencies:
5. Install dependencies:
```bash
dep ensure
```
Expand Down
10 changes: 5 additions & 5 deletions doc/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ buckets: # list of available buckets
transform: # and store it on disk
kind: "local-meta"
rootPath: "/var/www/domain/"

```
## Server
Expand Down Expand Up @@ -80,7 +79,6 @@ headers:
- statusCodes: [500, 503]
values:
"cache-control": "max-age=10, public"

```
## Buckets
Expand Down Expand Up @@ -116,7 +114,6 @@ buckets:
kind: "local-meta"
rootPath: "/Users/aldor/workspace/mkaciubacom/web"
pathPrefix: "transforms"

```
### Transform
Expand Down Expand Up @@ -210,11 +207,10 @@ Example definition
url: "http://remote/<container>/<item>"
headers:
"x-mort": 1

```
**url** - remote address, in url you should provide placeholders for bucket name (<conatiner>) and item path (<item>)
**headers* - addition request headers (optional)
**headers** - additional request headers (optional)
#### s3
Expand All @@ -230,9 +226,13 @@ Example definition
bucket: "mybucket" # optional
```
**accessKey** - S3 access key
**secretAccessKey** - S3 secret access key
**endpoint** - address of S3 service
**region** = region of s3 service
**bucket** - bucket used for storage, when empty name of bucket will be used
2 changes: 1 addition & 1 deletion scripts/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo "test" > /tmp/mort-tests/remote/file
MORT_PORT=8091
export MORT_PORT

go run cmd/mort/mort.go -config tests-int/config.yml > mort.logs &
go run cmd/mort/mort.go -config tests-int/config.yml &
pid=$!
sleep 15

Expand Down

0 comments on commit e485f32

Please sign in to comment.