mirror of
https://git.asonix.dog/asonix/pict-rs.git
synced 2024-11-24 18:41:06 +00:00
Merge pull request 'Add docker.' (#1) from Dessalines/pict-rs:add_docker into master
This commit is contained in:
commit
db8bdacd1c
8 changed files with 119 additions and 3 deletions
3
.dockerignore
Normal file
3
.dockerignore
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
target
|
||||||
|
.git
|
||||||
|
docker/dev/volumes
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
/target
|
/target
|
||||||
/data
|
/data
|
||||||
|
/docker/dev/volumes
|
||||||
|
|
18
README.md
18
README.md
|
@ -35,6 +35,24 @@ Running locally, port 8080, storing data in data/, and only allowing the `thumbn
|
||||||
$ ./pict-rs -a 127.0.0.1:8080 -p data/ -w thumbnail identity
|
$ ./pict-rs -a 127.0.0.1:8080 -p data/ -w thumbnail identity
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Docker
|
||||||
|
Run the following commands:
|
||||||
|
```
|
||||||
|
# Create a folder for the files (anywhere works)
|
||||||
|
mkdir /pict-rs
|
||||||
|
cd /pict-rs
|
||||||
|
wget https://git.asonix.dog/asonix/pict-rs/raw/branch/master/docker/prod/docker-compose.yml
|
||||||
|
sudo docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Docker Development
|
||||||
|
Run the following to develop in docker:
|
||||||
|
```
|
||||||
|
git clone https://git.asonix.dog/asonix/pict-rs
|
||||||
|
cd pict-rs/docker/dev
|
||||||
|
docker-compose up --build
|
||||||
|
```
|
||||||
|
|
||||||
### API
|
### API
|
||||||
pict-rs offers four endpoints:
|
pict-rs offers four endpoints:
|
||||||
- `POST /image` for uploading an image. Uploaded content must be valid multipart/form-data with an
|
- `POST /image` for uploading an image. Uploaded content must be valid multipart/form-data with an
|
||||||
|
|
30
docker/dev/Dockerfile
Normal file
30
docker/dev/Dockerfile
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Build
|
||||||
|
FROM ekidd/rust-musl-builder:1.44.0 as rust
|
||||||
|
|
||||||
|
# Cache deps
|
||||||
|
WORKDIR /app
|
||||||
|
RUN sudo chown -R rust:rust .
|
||||||
|
RUN USER=root cargo new server
|
||||||
|
WORKDIR /app/server
|
||||||
|
COPY Cargo.toml Cargo.lock ./
|
||||||
|
RUN sudo chown -R rust:rust .
|
||||||
|
RUN mkdir -p ./src/bin \
|
||||||
|
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
|
||||||
|
RUN cargo build --release
|
||||||
|
RUN rm -f ./target/x86_64-unknown-linux-musl/release/deps/pict_rs*
|
||||||
|
COPY src ./src/
|
||||||
|
|
||||||
|
# Build for release
|
||||||
|
RUN cargo build --frozen --release
|
||||||
|
|
||||||
|
FROM alpine:3.11
|
||||||
|
|
||||||
|
# Copy resources
|
||||||
|
COPY --from=rust /app/server/target/x86_64-unknown-linux-musl/release/pict-rs /app/pict-rs
|
||||||
|
|
||||||
|
RUN addgroup -g 1000 pictrs
|
||||||
|
RUN adduser -D -s /bin/sh -u 1000 -G pictrs pictrs
|
||||||
|
RUN chown pictrs:pictrs /app/pict-rs
|
||||||
|
USER pictrs
|
||||||
|
EXPOSE 8080
|
||||||
|
CMD ["/app/pict-rs"]
|
28
docker/dev/deploy.sh
Normal file
28
docker/dev/deploy.sh
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# To deploy, run ./deploy [tag]
|
||||||
|
#!/bin/sh
|
||||||
|
git checkout master
|
||||||
|
|
||||||
|
# Creating the new tag
|
||||||
|
new_tag="$1"
|
||||||
|
|
||||||
|
# Changing the docker-compose prod
|
||||||
|
sed -i "s/asonix\/pictrs:.*/asonix\/pictrs:$new_tag/" ../prod/docker-compose.yml
|
||||||
|
git add ../prod/docker-compose.yml
|
||||||
|
|
||||||
|
# The commit
|
||||||
|
git commit -m"Version $new_tag"
|
||||||
|
git tag $new_tag
|
||||||
|
|
||||||
|
# Rebuilding docker
|
||||||
|
docker-compose build
|
||||||
|
docker tag dev_pictrs:latest asonix/pictrs:x64-$new_tag
|
||||||
|
docker push asonix/pictrs:x64-$new_tag
|
||||||
|
|
||||||
|
# Build for Raspberry Pi / other archs
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
docker manifest push asonix/pictrs:$new_tag
|
||||||
|
|
||||||
|
# Push
|
||||||
|
git push origin $new_tag
|
||||||
|
git push
|
15
docker/dev/docker-compose.yml
Normal file
15
docker/dev/docker-compose.yml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
version: '3.3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
pictrs:
|
||||||
|
build:
|
||||||
|
context: ../../
|
||||||
|
dockerfile: docker/dev/Dockerfile
|
||||||
|
user: root
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8080:8080"
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- PICTRS_PATH=/app/data
|
||||||
|
volumes:
|
||||||
|
- ./volumes/pictrs:/app/data
|
13
docker/prod/docker-compose.yml
Normal file
13
docker/prod/docker-compose.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
version: '3.3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
pictrs:
|
||||||
|
image: asonix/pictrs:v0.0.1
|
||||||
|
user: root
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8080:8080"
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
- PICTRS_PATH=/app/data
|
||||||
|
volumes:
|
||||||
|
- ./volumes/pictrs:/app/data
|
|
@ -5,23 +5,31 @@ pub(crate) struct Config {
|
||||||
#[structopt(
|
#[structopt(
|
||||||
short,
|
short,
|
||||||
long,
|
long,
|
||||||
help = "The address and port the server binds to, e.g. 127.0.0.1:80"
|
env = "PICTRS_ADDR",
|
||||||
|
default_value = "0.0.0.0:8080",
|
||||||
|
help = "The address and port the server binds to. Default: 0.0.0.0:8080"
|
||||||
)]
|
)]
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
|
|
||||||
#[structopt(short, long, help = "The path to the data directory, e.g. data/")]
|
#[structopt(
|
||||||
|
short,
|
||||||
|
long,
|
||||||
|
env = "PICTRS_PATH",
|
||||||
|
help = "The path to the data directory, e.g. data/")]
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
|
|
||||||
#[structopt(
|
#[structopt(
|
||||||
short,
|
short,
|
||||||
long,
|
long,
|
||||||
help = "An image format to convert all uploaded files into, supports 'jpg' and 'png'"
|
env = "PICTRS_FORMAT",
|
||||||
|
help = "An optional image format to convert all uploaded files into, supports 'jpg' and 'png'"
|
||||||
)]
|
)]
|
||||||
format: Option<Format>,
|
format: Option<Format>,
|
||||||
|
|
||||||
#[structopt(
|
#[structopt(
|
||||||
short,
|
short,
|
||||||
long,
|
long,
|
||||||
|
env = "PICTRS_FILTER_WHITELIST",
|
||||||
help = "An optional list of filters to whitelist, supports 'identity', 'thumbnail', and 'blur'"
|
help = "An optional list of filters to whitelist, supports 'identity', 'thumbnail', and 'blur'"
|
||||||
)]
|
)]
|
||||||
whitelist: Option<Vec<String>>,
|
whitelist: Option<Vec<String>>,
|
||||||
|
|
Loading…
Reference in a new issue