Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI pipelines Nistagram Agent #24

Merged
merged 2 commits into from
Sep 14, 2021
Merged
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
54 changes: 54 additions & 0 deletions .github/workflows/ci-pr-develop-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# source: https://faun.pub/continuous-integration-of-java-project-with-github-actions-7a8a0e8246ef
name: CI operations PR event DEVELOP branch pipeline
on:
pull_request:
branches:
- develop
types: [opened, synchronize, reopened]
jobs:
# Test - Units & Integrations
test:
name: Test - Units & Integrations
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Maven Package
run: mvn -B clean package -DskipTests
#- name: Maven Verify
# run: mvn -B clean verify -Ptest

# Analyze code with Sonar Cloud
sonar_auth_service: # Generated using Sonar Cloud Maven build template
name: Test - SonarCloud scan (analysis) of auth service
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# -Pdev activate dev profile -f path/to/pom.xml
#run: mvn -Pdev -f -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=DevOps-Nistagram-Organization_Agent
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=DevOps-Nistagram-Organization_nistagram-agent-service
52 changes: 52 additions & 0 deletions .github/workflows/ci-push-develop-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# source: https://faun.pub/continuous-integration-of-java-project-with-github-actions-7a8a0e8246ef
name: CI operations PUSH event DEVELOP branch pipeline
on:
push:
branches:
- 'develop'
jobs:
# https://github.com/mathieudutour/github-tag-action
prerelease:
name: Create prerelease
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v5.6
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create a GitHub prerelease
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
release_name: Prerelease ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
prerelease: true
outputs:
tag_name: ${{ steps.tag_version.outputs.new_tag }}

artifact:
name: Publish - GitHub Packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Publish artifact on GitHub Packages
run: mvn -B clean deploy -DskipTests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker:
name: Publish - Docker Hub
runs-on: ubuntu-latest
needs: [prerelease]
steps:
- uses: actions/checkout@v1
- name: Build Nistagram Agent service docker image
run: bash ./publish-dockerhub.sh ${{ needs.prerelease.outputs.tag_name }} ${{ secrets.DOCKER_USER }} ${{ secrets.DOCKER_PASS }}
51 changes: 51 additions & 0 deletions .github/workflows/ci-push-main-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# source: https://faun.pub/continuous-integration-of-java-project-with-github-actions-7a8a0e8246ef
name: CI operations PUSH event MAIN branch pipeline
on:
push:
branches:
- 'main'
jobs:
# https://github.com/mathieudutour/github-tag-action
release:
name: Create release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v5.6
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Create a GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
outputs:
tag_name: ${{ steps.tag_version.outputs.new_tag }}

artifact:
name: Publish - GitHub Packages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Publish artifact on GitHub Packages
run: mvn -B clean deploy -DskipTests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker:
name: Publish - Docker Hub
runs-on: ubuntu-latest
needs: [release]
steps:
- uses: actions/checkout@v1
- name: Build Nistagram Agent service docker image
run: bash ./publish-dockerhub.sh ${{ needs.release.outputs.tag_name }} ${{ secrets.DOCKER_USER }} ${{ secrets.DOCKER_PASS }}
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<properties>
<java.version>1.8</java.version>
<appName>agent_service</appName>
<sonar.organization>devops-nistagram-organization</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<spring-cloud.version>2020.0.3</spring-cloud.version>
</properties>
<dependencies>
Expand Down Expand Up @@ -87,8 +89,20 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
</plugins>
<finalName>${appName}</finalName>
</build>
<distributionManagement>
<repository>
<id>github</id>
<name>Nistagram Agent service GitHub Package</name>
<url>https://maven.pkg.github.com/DevOps-Nistagram-Organization/nistagram-agent-service</url>
</repository>
</distributionManagement>

</project>
14 changes: 14 additions & 0 deletions publish-dockerhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

VERSION=${1}
DOCKERHUB_USERNAME=${2}
DOCKERHUB_PASSWORD=${3}


AGENT=${DOCKERHUB_USERNAME}/nistagram-agent-service:${VERSION}

DOCKER_BUILDKIT=1 docker build -t ${AGENT} --no-cache .

docker login --username ${DOCKERHUB_USERNAME} --password ${DOCKERHUB_PASSWORD}

docker push ${AGENT}