Skip to content
This repository was archived by the owner on Nov 23, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflow/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: DevOps java thin sample CI

on:
push:
branches:
- master
paths:
- pom.xml

jobs:
check:
runs-on: ubuntu-latest
# Default steps
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: "11"
distribution: "adopt"
- name: Build with Maven
run: mvn -B -P jenkins -gs configuration/settings.xml clean package
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile-cache
push: true
tags: |
kubespheresig/devops-java-sample-cache:latest
kubespheresig/devops-java-sample-cache:1.0.0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.settings/*
.classpath
target/*
artifacts/*
3 changes: 3 additions & 0 deletions Dockerfile-cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:3.13.5

COPY artifacts/m2/ /root/.m2/
14 changes: 7 additions & 7 deletions Jenkinsfile-on-prem
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ pipeline {
stage ('unit test') {
steps {
container ('maven') {
sh 'mvn clean -o -gs `pwd`/configuration/settings.xml test'
sh 'mvn -B -o -gs `pwd`/configuration/settings.xml clean test'
}
}
}

stage ('build & push') {
steps {
container ('maven') {
sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package'
sh 'mvn -o -B -gs `pwd`/configuration/settings.xml -Dmaven.test.skip=true clean package'
sh 'docker build -f Dockerfile-on-prem -t $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .'
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$HARBOR_CREDENTIAL_ID" ,)]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
sh 'docker push $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
sh 'docker push $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
}
}
}
Expand All @@ -53,8 +53,8 @@ pipeline {
}
steps{
container ('maven') {
sh 'docker tag $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:latest '
sh 'docker push $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:latest '
sh 'docker tag $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:latest '
sh 'docker push $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:latest '
}
}
}
Expand Down Expand Up @@ -83,8 +83,8 @@ pipeline {
sh 'git tag -a $TAG_NAME -m "$TAG_NAME" '
sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@gitlab.devops.kubesphere.local:30080/$GITLAB_ACCOUNT/devops-java-sample.git --tags --ipv4'
}
sh 'docker tag $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME '
sh 'docker push $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME '
sh 'docker tag $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME '
sh 'docker push $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:$TAG_NAME '
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Jenkinsfile-online
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ pipeline {
stage ('unit test') {
steps {
container ('maven') {
sh 'mvn clean -gs `pwd`/configuration/settings.xml test'
sh 'mvn -B -gs `pwd`/configuration/settings.xml clean test'
}
}
}

stage ('build & push') {
steps {
container ('maven') {
sh 'mvn -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package'
sh 'mvn -B -gs `pwd`/configuration/settings.xml -Dmaven.test.skip=true clean package'
sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .'
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$DOCKER_CREDENTIAL_ID" ,)]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
}
}
}
Expand All @@ -53,8 +53,8 @@ pipeline {
}
steps{
container ('maven') {
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
}
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ pipeline {
sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@github.com/$GITHUB_ACCOUNT/devops-java-sample.git --tags --ipv4'
}
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME '
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME '
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME '
}
}
}
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ For more information about how to use the KubeSphere DevOps system, you can refe
- [Create a Pipeline Using Graphical Editing Panels](https://kubesphere.io/docs/devops-user-guide/how-to-use/create-a-pipeline-using-graphical-editing-panel/)
- [Build and Deploy a Maven Project](https://kubesphere.io/docs/devops-user-guide/examples/a-maven-project/)
- [Source to Image: Publish an App without a Dockerfile](https://kubesphere.io/docs/project-user-guide/image-builder/source-to-image/)

1 change: 0 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ KubeSphere 基于 Jenkins 提供的 DevOps 系统可以实现[多种功能](http
- [使用图形编辑面板创建流水线](https://kubesphere.io/zh/docs/devops-user-guide/how-to-use/create-a-pipeline-using-graphical-editing-panel/)
- [构建和部署 Maven 工程](https://kubesphere.io/zh/docs/devops-user-guide/examples/a-maven-project/)
- [Source to Image:无需 Dockerfile 发布应用](https://kubesphere.io/zh/docs/project-user-guide/image-builder/source-to-image/)

12 changes: 9 additions & 3 deletions configuration/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<profile>
<id>jenkins</id>
<activation>
<activeByDefault>true</activeByDefault> <!-- change this to false, if you don't like to have it on per default -->
<activeByDefault>false</activeByDefault> <!-- change this to false, if you don't like to have it on per default -->
</activation>
<repositories>
<repository>
Expand All @@ -29,11 +29,17 @@
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror>
<mirror>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
Expand Down