Skip to content

Commit

Permalink
Merge branch 'swarm-deployment'
Browse files Browse the repository at this point in the history
  • Loading branch information
youngest committed Nov 16, 2021
2 parents 527dc9a + 161d95c commit bdbfe41
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 59 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
DOCKER_REGISTRY=staging-ec2.mlmodelscope.org:5000
DOCKER_REGISTRY=c3sr
API_VERSION=latest
UPLOADER_VERSION=latest
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ This repository provides the main parts of the mlmodelscope API

The `DOCKER_REGISTRY` environment variable must be set to build or pull
the correct image tags for development, staging, or production. The `.env`
file sets this to `staging-ec2.mlmodelscope.org:5000` by default, which
is the staging registry. This is safe to use for development as well. For
production it should be set to `c3sr` so that images will be tagged and
pulled from the C3SR namespace on Docker Hub.
file sets this to `c3sr` by default so that images will be tagged and
pulled from the C3SR namespace on Docker Hub. Change this if you want to
use a private registry to host your own modified images.

## API

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.9"
version: "3.8"
services:
api:
build:
Expand Down
49 changes: 49 additions & 0 deletions docker-compose.swarm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: "3.8"
services:
api:
networks:
- default
- traefik

deploy:
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik"
- "traefik.http.routers.mlmodelscope-api.rule=Host(`${ENVIRONMENT}api.mlmodelscope.org`)"
- "traefik.http.routers.mlmodelscope-api.entrypoints=websecure"
- "traefik.http.routers.mlmodelscope-api.tls.certresolver=letsencrypt"
- "traefik.http.services.mlmodelscope-api.loadbalancer.server.port=80"
- "traefik.http.middlewares.add-cors.headers.accessControlAllowMethods=GET,OPTIONS,PUT"
- "traefik.http.middlewares.add-cors.headers.accesscontrolalloworiginlist=https://staging.mlmodelscope.org,http://localhost:3000"
- "traefik.http.middlewares.add-cors.headers.accessControlAllowCredentials=true"
- "traefik.http.middlewares.add-cors.headers.accessControlAllowHeaders=origin,x-requested-with,content-type,accept,x-request-id"
- "traefik.http.middlewares.add-cors.headers.accesscontrolmaxage=100"
- "traefik.http.middlewares.add-cors.headers.addvaryheader=true"
- "traefik.http.routers.mlmodelscope-api.middlewares=add-cors"

uploader:
networks:
- default
- traefik

deploy:
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik"
- "traefik.http.routers.mlmodelscope-uploader.rule=Host(`${ENVIRONMENT}uploader.mlmodelscope.org`)"
- "traefik.http.routers.mlmodelscope-uploader.entrypoints=websecure"
- "traefik.http.routers.mlmodelscope-uploader.tls.certresolver=letsencrypt"
- "traefik.http.services.mlmodelscope-uploader.loadbalancer.server.port=80"
- "traefik.http.middlewares.add-cors-uploader.headers.accessControlAllowMethods=GET,OPTIONS,PUT,PATCH"
- "traefik.http.middlewares.add-cors-uploader.headers.accesscontrolalloworiginlist=https://staging.mlmodelscope.org"
- "traefik.http.middlewares.add-cors-uploader.headers.accessControlAllowCredentials=true"
- "traefik.http.middlewares.add-cors-uploader.headers.accessControlAllowHeaders=origin,x-requested-with,content-type,accept,x-request-id,tus-resumable,upload-length,upload-metadata,upload-offset"
- "traefik.http.middlewares.add-cors-uploader.headers.accesscontrolmaxage=100"
- "traefik.http.middlewares.add-cors-uploader.headers.addvaryheader=true"
- "traefik.http.routers.mlmodelscope-uploader.middlewares=add-cors-uploader"


networks:
traefik:
external:
name: traefik
51 changes: 3 additions & 48 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
version: "3.9"
version: "3.8"
services:
api:
image: "$DOCKER_REGISTRY/mlmodelscope-api:1.0"

networks:
- default
- traefik

deploy:
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik"
- "traefik.http.routers.mlmodelscope-api.rule=Host(`staging.api.mlmodelscope.org`)"
- "traefik.http.routers.mlmodelscope-api.entrypoints=websecure"
- "traefik.http.routers.mlmodelscope-api.tls.certresolver=letsencrypt"
- "traefik.http.services.mlmodelscope-api.loadbalancer.server.port=80"
- "traefik.http.middlewares.add-cors.headers.accessControlAllowMethods=GET,OPTIONS,PUT"
- "traefik.http.middlewares.add-cors.headers.accesscontrolalloworiginlist=https://staging.mlmodelscope.org,http://localhost:3000"
- "traefik.http.middlewares.add-cors.headers.accessControlAllowCredentials=true"
- "traefik.http.middlewares.add-cors.headers.accessControlAllowHeaders=origin,x-requested-with,content-type,accept,x-request-id"
- "traefik.http.middlewares.add-cors.headers.accesscontrolmaxage=100"
- "traefik.http.middlewares.add-cors.headers.addvaryheader=true"
- "traefik.http.routers.mlmodelscope-api.middlewares=add-cors"
image: "$DOCKER_REGISTRY/mlmodelscope-api:$API_VERSION"

environment:
- C3SR_REGISTRY_ENDPOINTS=registry:8500
Expand Down Expand Up @@ -53,31 +33,6 @@ services:
- "9411:9411"

uploader:
image: "$DOCKER_REGISTRY/mlmodelscope-uploader:1.0"
networks:
- default
- traefik

deploy:
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik"
- "traefik.http.routers.mlmodelscope-uploader.rule=Host(`staging.uploader.mlmodelscope.org`)"
- "traefik.http.routers.mlmodelscope-uploader.entrypoints=websecure"
- "traefik.http.routers.mlmodelscope-uploader.tls.certresolver=letsencrypt"
- "traefik.http.services.mlmodelscope-uploader.loadbalancer.server.port=80"
- "traefik.http.middlewares.add-cors-uploader.headers.accessControlAllowMethods=GET,OPTIONS,PUT,PATCH"
- "traefik.http.middlewares.add-cors-uploader.headers.accesscontrolalloworiginlist=https://staging.mlmodelscope.org"
- "traefik.http.middlewares.add-cors-uploader.headers.accessControlAllowCredentials=true"
- "traefik.http.middlewares.add-cors-uploader.headers.accessControlAllowHeaders=origin,x-requested-with,content-type,accept,x-request-id,tus-resumable,upload-length,upload-metadata,upload-offset"
- "traefik.http.middlewares.add-cors-uploader.headers.accesscontrolmaxage=100"
- "traefik.http.middlewares.add-cors-uploader.headers.addvaryheader=true"
- "traefik.http.routers.mlmodelscope-uploader.middlewares=add-cors-uploader"

image: "$DOCKER_REGISTRY/mlmodelscope-uploader:$UPLOADER_VERSION"
ports:
- "8089:80"

networks:
traefik:
external:
name: traefik
22 changes: 17 additions & 5 deletions scripts/build-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
cd `git rev-parse --show-toplevel`
source "scripts/functions.sh"

USAGE="Usage: ${0} <target>
USAGE="Usage: ${0} <target> <version> (registry)
target The service to build into a container, i.e. 'uploader':
> build.sh uploader"
target (required) The service to build into a container, i.e. 'uploader':
version (required) The version number to tag the image with
Note: image will always be tagged as 'latest'
registry (optional) The Docker registry to tag images against
Defaults to 'mlmodelscope-api'"

TARGET="$1"
TARGET_DIR="./$TARGET"
VERSION="$2"
REGISTRY="$3"
: ${REGISTRY:="mlmodelscope-api"}
DOCKERFILE="./docker/Dockerfile.$1"


if [ -z $TARGET ]; then
die_with_message "$USAGE"
fi
Expand All @@ -21,10 +28,15 @@ if [ ! -d "$TARGET" ]; then
die_with_message "Target ${TARGET} does not exist"
fi

if [ -z $VERSION ]; then
die_with_message "$USAGE"
fi

if [ ! -f "$DOCKERFILE" ]; then
die_with_message "Dockerfile ${DOCKERFILE} does not exist"
fi

docker build -t "mlmodelscope-api/$1:latest" --file "$DOCKERFILE" "$TARGET"
docker build -t "$REGISTRY/mlmodelscope-$TARGET:$VERSION" --file "$DOCKERFILE" "$TARGET_DIR"
docker tag "$REGISTRY/mlmodelscope-$TARGET:$VERSION" "$REGISTRY/mlmodelscope-$TARGET:latest"

cleanup_and_exit

0 comments on commit bdbfe41

Please sign in to comment.