Skip to content

Commit

Permalink
feat(ci): Update circle ci to match our needs
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 258 deletions.
285 changes: 38 additions & 247 deletions .circleci/config.yml
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: /.*/
8 changes: 8 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ you need to know about the utilization of ARA (don't hesitate to pass those doc

Please read the <<doc/developer/DeveloperDocumentation.adoc#head, Developer Documentation>>
to learn how the project is structured and how to develop new features in ARA and/or contribute.

== IDEAS

1. Circle CI to docker hub: make promote / think about adding unit tests process
2. Custom CI
3. Document dev cs prod process
4. Dockerize the dev environment

39 changes: 29 additions & 10 deletions code/Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
ifdef DOCKER_REPO
DOCKER_REGISTRY=$(DOCKER_REPO)/
endif
DOCKER_REGISTRY?=docker.io
# Forks may use name/ara for their tests
IMAGE_NAME?=ara
VERSION?=latest

DB_IMAGE=${DOCKER_REGISTRY}/${IMAGE_NAME}-db:${VERSION}
BACK_IMAGE=${DOCKER_REGISTRY}/${IMAGE_NAME}-back:${VERSION}
FRONT_IMAGE=${DOCKER_REGISTRY}/${IMAGE_NAME}-front:${VERSION}


cache-build-back:
@echo '-- Build java ara-back with local cache --'
@docker container run -v "$$PWD/back":/root/ara -w /root/ara maven:3-jdk-11 mvn -Pprod -s settings.xml clean package dependency:go-offline

build-db: ## Build ara-db
@echo '-- Build $(DOCKER_REGISTRY)ara-db:$(VERSION) --'
@docker build -t $(DOCKER_REGISTRY)ara-db:$(VERSION) data/instance
@echo '-- Build ${DB_IMAGE} --'
@docker build -t ${DB_IMAGE} data/instance

build-back: ## Build ara-back
@echo '-- Build $(DOCKER_REGISTRY)ara-back:$(VERSION) --'
@docker build -t $(DOCKER_REGISTRY)ara-back:$(VERSION) back
@echo '-- Build ${BACK_IMAGE} --'
@docker build -t ${BACK_IMAGE} back

build-front: ## Build ara-front
@echo '-- Build $(DOCKER_REGISTRY)ara-front:$(VERSION) --'
@docker build -t $(DOCKER_REGISTRY)ara-front:$(VERSION) front
@echo '-- Build ${FRONT_IMAGE} --'
@docker build -t ${FRONT_IMAGE} front

run-front: ## Run front
@echo '-- Run ara-front --'
Expand All @@ -36,9 +41,23 @@ build: build-back build-front build-db ## Build ARA
build-parallel: ## Build ARA in parallel
@$(MAKE) build -j3 -k

promote-back: ## promote ara back to specified registry
@echo '-- Push ${BACK_IMAGE} --'
@echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin ${DOCKER_REGISTRY}
@docker push ${BACK_IMAGE}
@docker logout

promote-front: ## promote ara back to specified registry
@echo '-- Push ${FRONT_IMAGE} --'
@echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin ${DOCKER_REGISTRY}
@docker push ${FRONT_IMAGE}
@docker logout

promote: promote-back promote-front ## Build ARA

start: ## Start ARA
@echo '-- Start ARA --'
@docker-compose up
@docker-compose up -d

stop: ## Stop ARA
@echo '-- Stop ARA --'
Expand Down
2 changes: 1 addition & 1 deletion code/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
- DATABASE_USER=root
- DATABASE_PASSWORD=to_change
- CLIENT_URL="http://ara-front/"
- DATA_DB_MODE=none # validate | update | create | create-drop
- DATA_DB_MODE=create-drop # validate | update | create | create-drop
- ARA_PROFILE=dev
networks:
- web_net
Expand Down

0 comments on commit b15da6e

Please sign in to comment.