-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Circle CI for building Docker
- Loading branch information
Showing
9 changed files
with
121 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# These environment variables must be set in CircleCI UI | ||
# | ||
# DOCKERHUB_REPO - docker hub repo, format: <username>/<repo> | ||
# DOCKER_USER - login info for docker hub | ||
# DOCKER_PASS | ||
# | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
- image: docker:stable-git | ||
auth: | ||
username: $DOCKER_USER | ||
password: $DOCKER_PASS | ||
working_directory: /dockerflow | ||
steps: | ||
- checkout | ||
- setup_remote_docker | ||
|
||
- run: | ||
name: Create a version.json | ||
command: | | ||
# create a version.json per https://github.com/mozilla-services/Dockerflow/blob/main/docs/version_object.md | ||
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \ | ||
"$CIRCLE_SHA1" \ | ||
"$CIRCLE_TAG" \ | ||
"$CIRCLE_PROJECT_USERNAME" \ | ||
"$CIRCLE_PROJECT_REPONAME" \ | ||
"$CIRCLE_BUILD_URL" > version.json | ||
- run: | ||
name: Login to Dockerhub | ||
command: | | ||
if [ "${DOCKER_USER}" == "" ] || [ "${DOCKER_PASS}" == "" ]; then | ||
echo "Skipping Login to Dockerhub, credentials not available." | ||
else | ||
echo "${DOCKER_PASS}" | docker login -u="${DOCKER_USER}" --password-stdin | ||
fi | ||
- run: | ||
name: Build Docker image | ||
command: docker build -t app:build . | ||
|
||
# save the built docker container into CircleCI's cache. This is | ||
# required since Workflows do not have the same remote docker instance. | ||
- run: | ||
name: docker save app:build | ||
command: mkdir -p /cache; docker save -o /cache/docker.tar "app:build" | ||
- save_cache: | ||
key: v1-{{ .Environment.CIRCLE_SHA1 }}-{{epoch}} | ||
paths: | ||
- /cache/docker.tar | ||
|
||
deploy: | ||
docker: | ||
- image: docker:18.02.0-ce | ||
auth: | ||
username: $DOCKER_USER | ||
password: $DOCKER_PASS | ||
steps: | ||
- setup_remote_docker | ||
- restore_cache: | ||
key: v1-{{.Environment.CIRCLE_SHA1}} | ||
- run: | ||
name: Restore Docker image cache | ||
command: docker load -i /cache/docker.tar | ||
|
||
- run: | ||
name: Deploy to Dockerhub | ||
command: | | ||
echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin | ||
# deploy main | ||
if [ "${CIRCLE_BRANCH}" == "main" ]; then | ||
docker tag app:build ${DOCKERHUB_REPO}:latest | ||
docker push ${DOCKERHUB_REPO}:latest | ||
elif [ ! -z "${CIRCLE_TAG}" ]; then | ||
# deploy a release tag... | ||
echo "${DOCKERHUB_REPO}:${CIRCLE_TAG}" | ||
docker tag app:build "${DOCKERHUB_REPO}:${CIRCLE_TAG}" | ||
docker images | ||
docker push "${DOCKERHUB_REPO}:${CIRCLE_TAG}" | ||
fi | ||
workflows: | ||
version: 2 | ||
build-test-deploy: | ||
jobs: | ||
- build | ||
- deploy: | ||
requires: | ||
- build | ||
filters: | ||
tags: | ||
only: /.*/ | ||
branches: | ||
only: main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,4 @@ | |
.idea | ||
|
||
# build | ||
.build | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
# Translation server | ||
# Translation service | ||
|
||
## Running | ||
1. Download models from https://github.com/mozilla/firefox-translations-models/tree/main/models/prod | ||
2. unzip | ||
3. git clone this repo | ||
4. git submodule update --init --recursive | ||
5. Point `MODELS_DIR=` in `docker-run.sh` to models directory (which contains directories like `enes`, `deen` etc.) | ||
5. bash docker-run.sh | ||
6. bash test.sh | ||
4. `bash MODELS_DIR=<path> scripts/run.sh` where `MODELS_DIR` is a path to models directory (which contains directories like `enes`, `deen` etc.) | ||
5. `bash scripts/test.sh` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
docker build -t translation-service . | ||
# docker run --name translation-service -it --rm -v $(pwd):/app -v $MODELS_DIR:/models -p 8080:8080 translation-service bash | ||
docker run --name translation-service -it --rm -v $MODELS_DIR:/models -p 8080:8080 translation-service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
curl http://0.0.0.0:8080/status | ||
|
||
curl --header "Content-Type: application/json" \ | ||
--request POST \ | ||
--data '{"from":"en", "to":"es", "text": "Rocket is a web framework for Rust. If youd like, you can think of Rocket as being a more flexible, friendly medley of Rails, Flask, Bottle, and Yesod. We prefer to think of Rocket as something new. Rocket aims to be fast, easy, and flexible while offering guaranteed safety and security where it can. Importantly, Rocket also aims to be fun, and it accomplishes this by ensuring that you write as little code as needed to accomplish your task."}' \ | ||
http://0.0.0.0:8080/v1/translate | ||
|
||
|
||
curl --header "Content-Type: application/json" \ | ||
--request POST \ | ||
--data '{"from":"es", "to":"en", "text": "Hola Mundo"}' \ | ||
http://0.0.0.0:8080/v1/translate |