CircleCI 2.0 改版看起來是簡單一點,文件也比較齊全,就把編譯指令改成2.0的吧
首先是原本專案目錄下的 circle.yml 不再用這個位置了
改成放在 .circleci/config.yml
內容如下 (cache部分改天再研究看看)
version: 2 jobs: build: working_directory: ~/test-rest docker: - image: circleci/openjdk:8-jdk steps: - checkout - setup_remote_docker # - restore_cache: # key: circleci-demo-java-spring-{{ checksum "pom.xml" }} # # - run: mvn dependency:go-offline # # - save_cache: # paths: # - ~/.m2 # key: circleci-demo-java-spring-{{ checksum "pom.xml" }} - run: gradle build - store_test_results: path: target/surefire-reports - store_artifacts: path: build/libs/test-rest-0.0.1-SNAPSHOT.jar - run: name: build and push Docker image command: | TAG=0.1.$CIRCLE_BUILD_NUM docker build -t spike234/test-rest:$TAG . docker login -u $DOCKER_USER -p $DOCKER_PASS docker push spike234/test-rest:$TAG
不用更新 Gradle 版本就可以正常編譯了
編譯 Docker Image 的 Dockerfile 如下
FROM java:8 label maintainer "spike19820318@gmail.com" ADD build/libs/test-rest-0.0.1-SNAPSHOT.jar app.jar EXPOSE 8080 ENV JAVA_OPTS="" ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]
指令也改成用 ENTRYPOINT
好吧~~就這樣簡單,來去玩 Kubernetes 了
要把這服務放在 Kubernetes 運行
cat << EOF > test-rest.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: test-rest-deployment spec: replicas: 1 template: metadata: labels: app: test-rest spec: containers: - name: test-rest image: spike234/test-rest:0.1.7 ports: - containerPort: 8080 resources: requests: cpu: 100m EOF kubectl create -f test-rest.yaml cat << EOF > test-rest-svc.yaml apiVersion: v1 kind: Service metadata: name: test-rest labels: app: test-rest spec: type: NodePort selector: app: test-rest ports: - port: 8080 targetPort: 8080 nodePort: 30080 EOF kubectl create -f test-rest-svc.yaml
收工~~
範例專案在這邊
https://github.com/samzhu/test-restReference:
CircleCIでGradleのテストを並列実行する - zephiransasのチラシの裏
CircleCI 2.0 では Docker ビルドキャッシュが効く - Qiita← 使用kubespray安裝Kubernetes 1.7