164 строки
5.9 KiB
YAML
164 строки
5.9 KiB
YAML
version: 2.0
|
|
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 version.json
|
|
command: |
|
|
# create a version.json per https://github.com/mozilla-services/Dockerflow/blob/master/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 blurts-server .
|
|
|
|
# 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 blurts-server
|
|
command: mkdir -p /cache; docker save -o /cache/docker.tar "blurts-server"
|
|
- save_cache:
|
|
key: v1-{{ .Branch }}-{{epoch}}
|
|
paths:
|
|
- /cache/docker.tar
|
|
|
|
test:
|
|
docker:
|
|
- image: docker:18.06.3-ce
|
|
steps:
|
|
- setup_remote_docker
|
|
- restore_cache:
|
|
key: v1-{{.Branch}}
|
|
- run:
|
|
name: Restore Docker image cache
|
|
command: docker load -i /cache/docker.tar
|
|
- run:
|
|
name: Update npm to latest
|
|
command: docker run blurts-server npm install npm@latest -g
|
|
- run:
|
|
name: Test Code
|
|
command: docker run blurts-server npm run lint
|
|
|
|
integration-test:
|
|
machine:
|
|
image: ubuntu-1604:201903-01
|
|
steps:
|
|
- checkout
|
|
- run:
|
|
name: Build and run tests.
|
|
command: |
|
|
export NVM_DIR="/opt/circleci/.nvm"
|
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
|
nvm use 10
|
|
node -v
|
|
cp .env-dist .env
|
|
npm install
|
|
npm install --only=dev
|
|
sudo chown -R $USER:$USER .
|
|
mkdir ./tests/integration/errorShots
|
|
docker-compose -f tests/integration/docker-compose.yml up --build -d
|
|
docker-compose -f tests/integration/docker-compose.yml exec --user root firefox npm run test:integration-headless-ci
|
|
- run:
|
|
name: Capture Logs.
|
|
when: on_fail
|
|
command: |
|
|
docker-compose -f tests/integration/docker-compose.yml logs server &> tests/integration/server.log
|
|
docker-compose -f tests/integration/docker-compose.yml logs postgres &> tests/integration/postgres.log
|
|
docker-compose -f tests/integration/docker-compose.yml logs firefox &> tests/integration/firefox.log
|
|
- store_artifacts:
|
|
path: ./tests/integration/errorShots/
|
|
- store_artifacts:
|
|
path: ./tests/integration/server.log
|
|
- store_artifacts:
|
|
path: ./tests/integration/postgres.log
|
|
- store_artifacts:
|
|
path: ./tests/integration/firefox.log
|
|
|
|
deploy:
|
|
docker:
|
|
- image: docker:18.06.3-ce
|
|
steps:
|
|
- setup_remote_docker
|
|
- restore_cache:
|
|
key: v1-{{.Branch}}
|
|
- 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 blurts-server ${DOCKERHUB_REPO}:latest
|
|
docker push ${DOCKERHUB_REPO}:latest
|
|
elif [ ! -z "${CIRCLE_TAG}" ]; then
|
|
# deploy a release tag...
|
|
echo "${DOCKERHUB_REPO}:${CIRCLE_TAG}"
|
|
docker tag blurts-server "${DOCKERHUB_REPO}:${CIRCLE_TAG}"
|
|
docker images
|
|
docker push "${DOCKERHUB_REPO}:${CIRCLE_TAG}"
|
|
fi
|
|
deploy_static:
|
|
docker:
|
|
- image: circleci/python:3.8
|
|
steps:
|
|
- checkout
|
|
- run:
|
|
name: Install AWS CLI
|
|
command: |
|
|
sudo pip install --upgrade pip
|
|
sudo pip install --upgrade awscli
|
|
- run:
|
|
name: Sync static content to S3
|
|
command: |
|
|
./.circleci/scripts/sync-static
|
|
|
|
workflows:
|
|
version: 2
|
|
build-test-deploy:
|
|
jobs:
|
|
- build:
|
|
filters:
|
|
tags:
|
|
only: /.*/
|
|
- deploy:
|
|
requires:
|
|
- build
|
|
filters:
|
|
tags:
|
|
only: /.*/
|
|
branches:
|
|
only: main
|
|
- deploy_static:
|
|
filters:
|
|
branches:
|
|
only: main
|
|
- integration-test:
|
|
requires:
|
|
- build
|
|
|