Skip to content

Commit

Permalink
CI (#8)
Browse files Browse the repository at this point in the history
Add Circle CI for building Docker
  • Loading branch information
eu9ene committed Dec 7, 2021
1 parent 31b876c commit c998c99
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 27 deletions.
96 changes: 96 additions & 0 deletions .circleci/config.yml
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
.idea

# build
.build
build
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN apt-get install -y libpcre2-dev

ADD ./src ./src
ADD ./3rd_party ./3rd_party
ADD ./compile.sh ./compile.sh
ADD ./scripts/compile.sh ./compile.sh
ADD ./.gitmodules ./.gitmodules
ADD ./.git ./.git
ADD ./CMakeLists.txt ./CMakeLists.txt
Expand Down
8 changes: 3 additions & 5 deletions README.md
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`
6 changes: 0 additions & 6 deletions docker-run.sh

This file was deleted.

2 changes: 2 additions & 0 deletions compile.sh → scripts/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

git submodule update --init --recursive

mkdir -p build
cd build
cmake ../ -DUSE_WASM_COMPATIBLE_SOURCES=off -DCOMPILE_CPU=on -DCMAKE_BUILD_TYPE=Release
Expand Down
4 changes: 4 additions & 0 deletions scripts/run.sh
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
14 changes: 14 additions & 0 deletions scripts/test.sh
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
14 changes: 0 additions & 14 deletions test.sh

This file was deleted.

0 comments on commit c998c99

Please sign in to comment.