add docker image

This commit is contained in:
Bruno Clermont
2017-06-22 20:56:17 +02:00
committed by Zlatko Čalušić
parent 6b821132ec
commit 07b6d5facf
6 changed files with 112 additions and 0 deletions

View File

@@ -22,6 +22,8 @@ performance [improvements](https://github.com/restic/restic/commit/04b262d8f10ba
## Installation ## Installation
### From source
Run ```go run build.go```, afterwards you'll find the binary in the current directory. You can move it anywhere you Run ```go run build.go```, afterwards you'll find the binary in the current directory. You can move it anywhere you
want. There's also an [example systemd service want. There's also an [example systemd service
file](https://github.com/restic/rest-server/blob/master/etc/rest-server.service) included, so you can get it up & file](https://github.com/restic/rest-server/blob/master/etc/rest-server.service) included, so you can get it up &
@@ -49,8 +51,20 @@ Flags:
Alternatively, you can compile and install it in your $GOBIN with a standard `go install`. But, beware, you won't have Alternatively, you can compile and install it in your $GOBIN with a standard `go install`. But, beware, you won't have
version info built into binary, when compiled that way. version info built into binary, when compiled that way.
#### Build Docker Image
Run `docker/build.sh`, image name is `restic/rest-server:latest`.
### From Docker image
```
docker pull restic/rest-server:latest
```
## Getting started ## Getting started
### Using binary
By default the server persists backup data in `/tmp/restic`. Start the server with a custom persistence directory: By default the server persists backup data in `/tmp/restic`. Start the server with a custom persistence directory:
``` ```
@@ -82,6 +96,40 @@ and via HTTP, even simultaneously.
To learn how to use restic backup client with REST backend, please consult [restic To learn how to use restic backup client with REST backend, please consult [restic
manual](https://restic.readthedocs.io/en/latest/manual.html#rest-server). manual](https://restic.readthedocs.io/en/latest/manual.html#rest-server).
### Using Docker image
By default, image use authentication. To turn it off, set environment variable `DISABLE_AUTHENTICATION` to any value.
Persistent data volume is located to `/data`
#### Start server
```
docker run --name myserver -v /my/data:/data restic/rest-server
```
It's suggested to set a name to more easily manage users (see next section).
#### Manager users
##### Add user
```
docker exec -ti myserver create_user myuser
```
or
```
docker exec -ti myserver create_user myuser mypassword
```
##### Delete user
```
docker exec myserver delete_user myuser
```
## Why use Rest Server? ## Why use Rest Server?
Compared to the SFTP backend, the REST backend has better performance, especially so if you can skip additional crypto Compared to the SFTP backend, the REST backend has better performance, especially so if you can skip additional crypto

14
docker/Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
FROM alpine:3.6
RUN apk add --no-cache --update apache2-utils
COPY docker/*_user rest-server /usr/bin/
COPY docker/entry.sh /
ENV DATA_DIRECTORY=/data
ENV PASSWORD_FILE=/data/.htpasswd
VOLUME /data
EXPOSE 80
ENTRYPOINT ["/entry.sh"]

11
docker/build.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/sh
set -e
echo "Build binary using golang docker image"
docker run --rm -ti \
-v `pwd`:/go/src/github.com/restic/rest-server \
-w /go/src/github.com/restic/rest-server golang:1.8.3-alpine go run build.go
echo "Build docker image restic/rest-server:latest"
docker build --rm -t restic/rest-server:latest -f docker/Dockerfile .

10
docker/create_user Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
if [ -z "$1" ]; then
echo "create_user [username]"
echo "or"
echo "create_user [username] [password]"
exit 1
fi
htpasswd -s $PASSWORD_FILE $1 $2

8
docker/delete_user Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
if [ -z "$1" ]; then
echo "delete_user [username]"
exit 1
fi
htpasswd -D $PASSWORD_FILE $1

21
docker/entry.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/sh
set -e
mkdir -p $DATA_DIRECTORY
if [ -z "$DISABLE_AUTHENTICATION" ]; then
if [ ! -f $PASSWORD_FILE ]; then
touch $PASSWORD_FILE
fi
if [ ! -s $PASSWORD_FILE ]; then
echo
echo "**WARNING** No user exists, please 'docker exec -ti \$CONTAINER_ID create_user'"
echo
fi
else
rm -f $PASSWORD_FILE
fi
rest-server --listen ":80" --path $DATA_DIRECTORY