Skip to content

Commit 7c49bdd

Browse files
authored
CircleCI migration from 1.0 to 2.0 (#333)
* migration to circleci 2.0 config * install docker compose * add setup remote docker * comment out docker compose * using public petstore for testing * use only one working_directory * use openapitools/openapi-petstore instead * disable auth in petstore server * run petstore server locally via mvn jetty * fix typo * test go first * test pet server at port 8080 * remove docker compose command * wait for server to start up * sleep longer * test mvn jetty again * use machine executor * comment out docker * comment out restore cache * sleep for 30s * change petstore port * restore petstore docker * fix docker run command * restore cache, clean up comments
1 parent c607ea8 commit 7c49bdd

1 file changed

Lines changed: 93 additions & 54 deletions

File tree

circle.yml

Lines changed: 93 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,93 @@
1-
# Java-related client, server tests
2-
machine:
3-
java:
4-
version: openjdk8
5-
services:
6-
- docker
7-
# Override /etc/hosts
8-
hosts:
9-
petstore.swagger.io: 127.0.0.1
10-
environment:
11-
DOCKER_GENERATOR_IMAGE_NAME: openapitools/openapi-generator
12-
DOCKER_CODEGEN_CLI_IMAGE_NAME: openapitools/openapi-generator-cli
13-
14-
dependencies:
15-
cache_directories:
16-
- "~/.m2"
17-
- "~/.sbt"
18-
- "~/.ivy2"
19-
20-
pre:
21-
- sudo add-apt-repository ppa:duggan/bats --yes
22-
- sudo apt-get update -qq
23-
- sudo apt-get install -qq bats
24-
- sudo apt-get install -qq curl
25-
# to run petstore server locally via docker
26-
- docker pull swaggerapi/petstore
27-
- docker run -d -e SWAGGER_HOST=http://petstore.swagger.io -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/petstore
28-
- docker ps -a
29-
# show host table to confirm petstore.swagger.io is mapped to localhost
30-
- cat /etc/hosts
31-
override:
32-
- cp CI/pom.xml.circleci pom.xml
33-
34-
test:
35-
override:
36-
## test with jdk8
37-
- java -version
38-
- mvn --quiet clean install
39-
- mvn --quiet verify -Psamples
40-
# skip the rest if previous mvn task fails
41-
- if [ $? -ne 0 ]; then exit 1; fi
42-
## test with jdk7
43-
- sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
44-
- java -version
45-
- cp CI/pom.xml.circleci.java7 pom.xml # use jdk7 pom
46-
- mvn --quiet clean install
47-
- mvn --quiet verify -Psamples
48-
# skip the rest if previous mvn task fails
49-
- if [ $? -ne 0 ]; then exit 1; fi
50-
## docker push done in Travis instead
51-
## docker: build generator image and push to Docker Hub
52-
#- if [ $DOCKER_HUB_USERNAME ]; then docker login --email=$DOCKER_HUB_EMAIL --username=$DOCKER_HUB_USERNAME --password=$DOCKER_HUB_PASSWORD && docker build --rm=false -t $DOCKER_GENERATOR_IMAGE_NAME ./modules/opeanapi-generator && if [ ! -z "$CIRCLE_TAG" ]; then docker tag $DOCKER_GENERATOR_IMAGE_NAME:latest $DOCKER_GENERATOR_IMAGE_NAME:$CIRCLE_TAG; fi && if [ ! -z "$CIRCLE_TAG" ] || [ "$CIRCLE_BRANCH" = "master" ]; then docker push $DOCKER_GENERATOR_IMAGE_NAME; fi; fi
53-
### docker: build cli image and push to Docker Hub
54-
#- if [ $DOCKER_HUB_USERNAME ]; then docker login --email=$DOCKER_HUB_EMAIL --username=$DOCKER_HUB_USERNAME --password=$DOCKER_HUB_PASSWORD && docker build --rm=false -t $DOCKER_CODEGEN_CLI_IMAGE_NAME ./modules/openapi-generator-cli && if [ ! -z "$CIRCLE_TAG" ]; then docker tag $DOCKER_CODEGEN_CLI_IMAGE_NAME:latest $DOCKER_CODEGEN_CLI_IMAGE_NAME:$CIRCLE_TAG; fi && if [ ! -z "$CIRCLE_TAG" ] || [ "$CIRCLE_BRANCH" = "master" ]; then docker push $DOCKER_CODEGEN_CLI_IMAGE_NAME; fi; fi
1+
version: 2
2+
jobs:
3+
build:
4+
machine:
5+
docker_layer_caching: true
6+
working_directory: ~/OpenAPITools/openapi-generator
7+
parallelism: 1
8+
shell: /bin/bash --login
9+
environment:
10+
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
11+
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
12+
DOCKER_GENERATOR_IMAGE_NAME: openapitools/openapi-generator
13+
DOCKER_CODEGEN_CLI_IMAGE_NAME: openapitools/openapi-generator-cli
14+
steps:
15+
# Machine Setup
16+
# If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each
17+
# The following `checkout` command checks out your code to your working directory. In 1.0 we did this implicitly. In 2.0 you can choose where in the course of a job your code should be checked out.
18+
- checkout
19+
# Prepare for artifact and test results collection equivalent to how it was done on 1.0.
20+
# In many cases you can simplify this from what is generated here.
21+
# 'See docs on artifact collection here https://circleci.com/docs/2.0/artifacts/'
22+
- run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
23+
# This is based on your 1.0 configuration file or project settings
24+
- run:
25+
command: sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java; sudo update-alternatives --set javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac; echo -e "export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64" >> $BASH_ENV
26+
- run:
27+
command: 'sudo docker info >/dev/null 2>&1 || sudo service docker start; '
28+
- run:
29+
command: |-
30+
printf '127.0.0.1 petstore.swagger.io
31+
' | sudo tee -a /etc/hosts
32+
# Dependencies
33+
# This would typically go in either a build or a build-and-test job when using workflows
34+
# Restore the dependency cache
35+
- restore_cache:
36+
keys:
37+
# This branch if available
38+
- v1-dep-{{ .Branch }}-
39+
# Default branch if not
40+
- v1-dep-master-
41+
# This is based on your 1.0 configuration file or project settings
42+
- run: sudo add-apt-repository ppa:duggan/bats --yes
43+
- run: sudo apt-get update -qq
44+
- run: sudo apt-get install -qq bats
45+
- run: sudo apt-get install -qq curl
46+
# - run: docker pull openapitools/openapi-petstore
47+
# - run: docker run -d -e OPENAPI_BASE_PATH=/v3 -e DISABLE_API_KEY=1 -e DISABLE_OAUTH=1 -p 80:8080 openapitools/openapi-petstore
48+
- run: docker pull swaggerapi/petstore
49+
- run: docker run -d -e SWAGGER_HOST=http://petstore.swagger.io -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/petstore
50+
- run: docker ps -a
51+
- run: sleep 30
52+
- run: cat /etc/hosts
53+
# This is based on your 1.0 configuration file or project settings
54+
- run: cp CI/pom.xml.circleci pom.xml
55+
# Save dependency cache
56+
- save_cache:
57+
key: v1-dep-{{ .Branch }}
58+
paths:
59+
# This is a broad list of cache paths to include many possible development environments
60+
# You can probably delete some of these entries
61+
- vendor/bundle
62+
- ~/virtualenvs
63+
- ~/.m2
64+
- ~/.ivy2
65+
- ~/.bundle
66+
- ~/.go_workspace
67+
- ~/.gradle
68+
- ~/.cache/bower
69+
# These cache paths were specified in the 1.0 config
70+
- ~/.sbt
71+
# Test
72+
# This would typically be a build job when using workflows, possibly combined with build
73+
# This is based on your 1.0 configuration file or project settings
74+
- run: java -version
75+
- run: mvn --quiet clean install
76+
- run: mvn --quiet verify -Psamples
77+
- run: if [ $? -ne 0 ]; then exit 1; fi
78+
- run: sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
79+
- run: java -version
80+
- run: cp CI/pom.xml.circleci.java7 pom.xml
81+
- run: mvn --quiet clean install
82+
- run: mvn --quiet verify -Psamples
83+
- run: if [ $? -ne 0 ]; then exit 1; fi
84+
# Teardown
85+
# If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each
86+
# Save test results
87+
- store_test_results:
88+
path: /tmp/circleci-test-results
89+
# Save artifacts
90+
- store_artifacts:
91+
path: /tmp/circleci-artifacts
92+
- store_artifacts:
93+
path: /tmp/circleci-test-results

0 commit comments

Comments
 (0)