Replace Bamboo SCDF samples build w/ GitHub actions (#159)

Add GitHub actions based CI pipeline

Resolves #155
This commit is contained in:
Chris Bono
2022-01-21 11:31:06 -06:00
committed by GitHub
parent 547f87027b
commit ef1a52efd9
11 changed files with 501 additions and 91 deletions

View File

@@ -0,0 +1,76 @@
name: 'Build Sample App'
description: 'Builds a sample app and optionally publishes to Artifactory and pushes to a Docker registry'
inputs:
app-dir:
description: 'relative path to the app directory'
required: true
mvn-build-commands:
description: 'commands passed to \"mvnw" to build the app'
required: false
default: '-B clean verify'
artifactory-publish:
description: 'whether or not to publish to artifactory'
required: false
default: 'false'
jf-artifactory-spring:
description: 'encoded JFrog server id configuration'
required: false
jf-mvn-build-commands:
description: 'commands passed to \"jfrog rt mvn\" to publish the app'
required: false
default: '-B clean install -DskipTests'
docker-push:
description: 'whether or not to push docker image to docker hub'
required: false
default: 'false'
docker-registry:
description: 'docker registry'
required: false
docker-username:
description: 'docker username'
required: false
docker-password:
description: 'docker password'
required: false
docker-images:
description: 'csv of docker images to push'
required: false
docker-images-override:
description: 'csv of docker image tags to use when pushing (parallel array to docker-images)'
required: false
runs:
using: "composite"
steps:
- uses: actions/checkout@v2
- uses: jvalkeal/setup-maven@v1
with:
maven-version: 3.8.4
- uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 8
cache: maven
- name: Maven build
shell: bash
run: ./mvnw ${{ inputs.mvn-build-commands }}
working-directory: ${{ inputs.app-dir }}
- uses: ./.github/actions/build-sample-app/artifactory-publish
if: ${{ inputs.artifactory-publish == 'true' }}
with:
app-dir: ${{ inputs.app-dir }}
jf-artifactory-spring: ${{ inputs.jf-artifactory-spring }}
jf-mvn-build-commands: ${{ inputs.jf-mvn-build-commands }}
- uses: ./.github/actions/build-sample-app/docker-push
if: ${{ inputs.docker-push == 'true' }}
with:
app-dir: ${{ inputs.app-dir }}
docker-registry: ${{ inputs.docker-registry }}
docker-username: ${{ inputs.docker-username }}
docker-password: ${{ inputs.docker-password }}
docker-images: ${{ inputs.docker-images }}
docker-images-override: ${{ inputs.docker-images-override }}

View File

@@ -0,0 +1,45 @@
name: 'Sample App Publish'
description: 'Publishes a sample app to Artifactory'
inputs:
app-dir:
description: 'relative path to the app directory'
required: true
jf-artifactory-spring:
description: 'encoded JFrog server id configuration'
required: true
jf-mvn-build-commands:
description: 'commands passed to \"jfrog rt mvn\" to publish the app'
required: false
default: '-B clean install -DskipTests'
runs:
using: "composite"
steps:
- name: Setup JFrog CLI
uses: jfrog/setup-jfrog-cli@v1
with:
version: 1.46.4
env:
JF_ARTIFACTORY_SPRING: ${{ inputs.jf-artifactory-spring }}
- name: Configure JFrog Cli
shell: bash
run: |
jfrog rt mvnc \
--server-id-resolve=repo.spring.io \
--server-id-deploy=repo.spring.io \
--repo-resolve-releases=libs-milestone \
--repo-resolve-snapshots=libs-snapshot \
--repo-deploy-releases=release \
--repo-deploy-snapshots=snapshot
echo JFROG_CLI_BUILD_NAME=spring-cloud-dataflow-samples >> $GITHUB_ENV
echo JFROG_CLI_BUILD_NUMBER=$GITHUB_RUN_NUMBER >> $GITHUB_ENV
working-directory: ${{ inputs.app-dir }}
- name: Publish to Artifactory
shell: bash
run: |
jfrog rt mvn ${{ inputs.jf-mvn-build-commands }}
jfrog rt build-publish
working-directory: ${{ inputs.app-dir }}

View File

@@ -0,0 +1,73 @@
name: 'Sample App Push'
description: 'Pushes a containerized sample app to Docker'
inputs:
app-dir:
description: 'relative path to the app directory'
required: true
docker-registry:
description: 'docker registry'
required: false
docker-username:
description: 'docker username'
required: true
docker-password:
description: 'docker password'
required: true
docker-images:
description: 'csv of docker images to push'
required: true
docker-images-override:
description: 'csv of docker image tags to use when pushing (parallel array to docker-images)'
required: false
runs:
using: "composite"
steps:
- name: Login Dockerhub
uses: docker/login-action@v1
with:
registry: ${{ inputs.docker-registry }}
username: ${{ inputs.docker-username }}
password: ${{ inputs.docker-password }}
- name: Push images to Dockerhub
env:
DOCKER_REGISTRY: ${{ inputs.docker-registry }}
DOCKER_IMAGES: ${{ inputs.docker-images }}
DOCKER_IMAGES_OVERRIDE: ${{ inputs.docker-images-override }}
working-directory: ${{ inputs.app-dir }}
shell: bash
run: |
# read the images into arrays
read -r -a images <<< "$DOCKER_IMAGES"
read -r -a imagesOverride <<< "$DOCKER_IMAGES_OVERRIDE"
# validate lengths if override specified
numImages=${#images[@]}
numImagesOverride=${#imagesOverride[@]}
if [[ $numImagesOverride -gt 0 && $numImages -ne $numImagesOverride ]]; then
echo "when 'docker-images-override' is specified it must be the same length as 'docker-images'"
exit 1
fi
# determine the target images name based on registry and override
for idx in "${!images[@]}"
do
# use override if specified
if [[ $numImagesOverride -gt 0 ]]; then
image="${imagesOverride[idx]}"
else
image="${images[idx]}"
fi
# pre-pend registry if specified
if [[ "$DOCKER_REGISTRY" != "" ]]; then
image="$DOCKER_REGISTRY/$image"
fi
# tag the original image if it has changed (override and/or registry)
originalImage="${images[idx]}"
if [[ "$image" != "$originalImage" ]]; then
docker tag ${originalImage} ${image}
fi
docker push ${image}
done