-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): Update circle ci to match our needs
We want cci to work with the new dockerized project We also want to get a simple process: build and deploy on new tags anly
- Loading branch information
regislegrand
committed
Jun 26, 2020
1 parent
5c84340
commit b15da6e
Showing
4 changed files
with
76 additions
and
258 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 |
---|---|---|
@@ -1,256 +1,47 @@ | ||
version: 2.1 | ||
executors: | ||
docker-publisher: | ||
environment: | ||
DATABASE_IMAGE_NAME: decathlon/ara-db | ||
SERVER_IMAGE_NAME: decathlon/ara-server | ||
docker: | ||
- image: circleci/openjdk:8u222-stretch | ||
client-builder: | ||
docker: | ||
- image: circleci/node:10 | ||
jobs: | ||
build_client: | ||
executor: client-builder | ||
working_directory: ~/ara/client | ||
steps: | ||
# Beware! Even though the working_directory is set as ~/ara/client, the client directory cannot be accessed unless adding the checkout below | ||
# You can get more details from this link: https://stackoverflow.com/questions/50570221/circleci-2-0-working-with-subdirectory | ||
- checkout: | ||
path: ~/ara | ||
- run: | ||
name: Install client's dependencies | ||
command: npm install | ||
- run: | ||
name: Build client | ||
command: npm run build | ||
build_app: | ||
executor: docker-publisher | ||
working_directory: ~/ara | ||
steps: | ||
- checkout | ||
- restore_cache: | ||
key: ara-{{ checksum "pom.xml" }} | ||
- run: | ||
name: Build Jar | ||
command: mvn package dependency:go-offline | ||
- save_cache: | ||
paths: | ||
- ~/.m2 | ||
key: ara-{{ checksum "pom.xml" }} | ||
- store_test_results: | ||
path: server/target/surefire-reports | ||
- persist_to_workspace: | ||
root: . | ||
paths: | ||
- ./database/instance | ||
- ./final | ||
build_latest_images: | ||
executor: docker-publisher | ||
working_directory: ~/ara | ||
steps: | ||
- attach_workspace: | ||
at: /tmp/workspace | ||
- setup_remote_docker: | ||
docker_layer_caching: false | ||
- run: | ||
name: Build Docker images | ||
command: | | ||
docker build -t $DATABASE_IMAGE_NAME:latest /tmp/workspace/database/instance | ||
docker build -t $SERVER_IMAGE_NAME:latest /tmp/workspace/final | ||
- run: | ||
name: Archive Docker images | ||
command: | | ||
docker save -o database-image.tar $DATABASE_IMAGE_NAME | ||
docker save -o server-image.tar $SERVER_IMAGE_NAME | ||
- persist_to_workspace: | ||
root: . | ||
paths: | ||
- ./database-image.tar | ||
- ./server-image.tar | ||
build_nightly_images: | ||
executor: docker-publisher | ||
working_directory: ~/ara | ||
steps: | ||
- attach_workspace: | ||
at: /tmp/workspace | ||
- setup_remote_docker: | ||
docker_layer_caching: false | ||
- run: | ||
name: Build Docker images | ||
command: | | ||
docker build -t $DATABASE_IMAGE_NAME:nightly /tmp/workspace/database/instance | ||
docker build -t $SERVER_IMAGE_NAME:nightly /tmp/workspace/final | ||
- run: | ||
name: Archive Docker images | ||
command: | | ||
docker save -o database-image.tar $DATABASE_IMAGE_NAME | ||
docker save -o server-image.tar $SERVER_IMAGE_NAME | ||
- persist_to_workspace: | ||
root: . | ||
paths: | ||
- ./database-image.tar | ||
- ./server-image.tar | ||
nightly: | ||
executor: docker-publisher | ||
|
||
# Remember to set the following variables to the circleci project: | ||
# - DOCKER_REGISTRY optional, default to docker.io | ||
# - IMAGE_NAME optional, default to ara (use username/ara to make tests from a forked repo) | ||
# - DOCKER_USERNAME | ||
# - DOCKER_PASSWORD | ||
|
||
commands: | ||
define_env: | ||
steps: | ||
- run: | ||
name: Create nightly version tag | ||
command: echo "${CIRCLE_BRANCH/version\//''}-nightly" > version.txt | ||
- persist_to_workspace: | ||
root: . | ||
paths: | ||
- ./version.txt | ||
release: | ||
executor: docker-publisher | ||
- run: echo "if [ -z ${CIRCLE_TAG} ]; then VERSION=develop; else VERSION=${CIRCLE_TAG}; fi; export VERSION" > ${BASH_ENV} | ||
make_build: | ||
steps: | ||
- run: | ||
name: Create release version tag | ||
command: echo "${CIRCLE_TAG/v/''}" > version.txt | ||
- persist_to_workspace: | ||
root: . | ||
paths: | ||
- ./version.txt | ||
publish_latest: | ||
executor: docker-publisher | ||
- run: make -C code build | ||
make_promote: | ||
steps: | ||
- attach_workspace: | ||
at: /tmp/workspace | ||
- setup_remote_docker | ||
- run: | ||
name: Load archived Docker images | ||
command: | | ||
docker load -i /tmp/workspace/database-image.tar | ||
docker load -i /tmp/workspace/server-image.tar | ||
- run: | ||
name: Publish Docker Images to Docker Hub | ||
command: | | ||
echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin | ||
IMAGE_TAG=$(cat /tmp/workspace/version.txt) | ||
docker push $DATABASE_IMAGE_NAME:latest | ||
docker push $SERVER_IMAGE_NAME:latest | ||
docker tag $DATABASE_IMAGE_NAME:latest $DATABASE_IMAGE_NAME:$IMAGE_TAG | ||
docker tag $SERVER_IMAGE_NAME:latest $SERVER_IMAGE_NAME:$IMAGE_TAG | ||
docker push $DATABASE_IMAGE_NAME:$IMAGE_TAG | ||
docker push $SERVER_IMAGE_NAME:$IMAGE_TAG | ||
# FAIL IF CREDENTIALS ARE NOT SET | ||
- run: > | ||
test ${DOCKER_USERNAME} && test ${DOCKER_PASSWORD} || ( echo "Credentials are missing, leaving ..." && exit 1 ) | ||
# PROMOTE ONLY TAGS | ||
- run: > | ||
test ${CIRCLE_TAG} && make -C code promote || echo "TAG not set, skipping" | ||
executors: | ||
docker-executor: | ||
docker: | ||
- image: cimg/base:2020.01 | ||
|
||
jobs: | ||
build_promote: | ||
executor: docker-executor | ||
steps: | ||
- checkout | ||
- setup_remote_docker # needed to run docker from container | ||
- define_env | ||
- make_build | ||
- make_promote | ||
|
||
publish_nightly: | ||
executor: docker-publisher | ||
steps: | ||
- attach_workspace: | ||
at: /tmp/workspace | ||
- setup_remote_docker | ||
- run: | ||
name: Load archived Docker images | ||
command: | | ||
docker load -i /tmp/workspace/database-image.tar | ||
docker load -i /tmp/workspace/server-image.tar | ||
- run: | ||
name: Publish Docker Images to Docker Hub | ||
command: | | ||
echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin | ||
docker push $DATABASE_IMAGE_NAME:nightly | ||
docker push $SERVER_IMAGE_NAME:nightly | ||
workflows: | ||
version: 2 | ||
build-pr: | ||
jobs: | ||
- build_client: | ||
filters: | ||
branches: | ||
ignore: /(^version\/.*)|master/ | ||
- build_app: | ||
filters: | ||
branches: | ||
ignore: /(^version\/.*)|master/ | ||
requires: | ||
- build_client | ||
build-master: | ||
jobs: | ||
- build_client: | ||
filters: | ||
branches: | ||
only: master | ||
- build_app: | ||
filters: | ||
branches: | ||
only: master | ||
- build_latest_images: | ||
filters: | ||
branches: | ||
only: master | ||
requires: | ||
- build_client | ||
- build_app | ||
build-nightly: | ||
build_and_may_promote: | ||
jobs: | ||
- build_client: | ||
filters: | ||
branches: | ||
only: /^version\/.*/ | ||
- build_app: | ||
filters: | ||
branches: | ||
only: /^version\/.*/ | ||
- build_nightly_images: | ||
filters: | ||
branches: | ||
only: /^version\/.*/ | ||
requires: | ||
- build_client | ||
- build_app | ||
- nightly: | ||
filters: | ||
branches: | ||
only: /^version\/.*/ | ||
- publish_nightly: | ||
context: ara-context | ||
requires: | ||
- build_client | ||
- build_app | ||
- build_nightly_images | ||
- nightly | ||
filters: | ||
branches: | ||
only: /^version\/.*/ | ||
build-release: | ||
jobs: | ||
- build_client: | ||
filters: | ||
tags: | ||
only: /^v.*/ | ||
branches: | ||
ignore: /.*/ | ||
- build_app: | ||
filters: | ||
tags: | ||
only: /^v.*/ | ||
branches: | ||
ignore: /.*/ | ||
- build_latest_images: | ||
filters: | ||
tags: | ||
only: /^v.*/ | ||
branches: | ||
ignore: /.*/ | ||
requires: | ||
- build_client | ||
- build_app | ||
- release: | ||
filters: | ||
tags: | ||
only: /^v.*/ | ||
branches: | ||
ignore: /.*/ | ||
- publish_latest: | ||
context: ara-context | ||
requires: | ||
- build_client | ||
- build_app | ||
- build_latest_images | ||
- release | ||
filters: | ||
- build_promote: # TAGS NOT RUN BY DEFAULT | ||
filters: | ||
tags: | ||
only: /^v.*/ | ||
branches: | ||
ignore: /.*/ | ||
only: /.*/ |
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
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