Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
- Rewrite workflows with reusable workflows
- Rename compose files to compose.yml
  • Loading branch information
hyness committed Apr 4, 2024
1 parent cbbd2db commit d3aa683
Show file tree
Hide file tree
Showing 36 changed files with 430 additions and 162 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/build-and-deploy-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build and deploy OCI image to registry

on:
workflow_call:
inputs:
image-jvm-type:
description: JVM type for output image
type: string
default: jre
image-jvm-version:
description: JVM version for output image
type: string
default: 17
image-name:
description: The output image name
type: string
required: true
java-build-distribution:
description: Java distribution to use for build
type: string
default: temurin
java-build-version:
description: Java version to build with
type: string
default: 17
registry:
description: The registry to deploy to
type: string
required: true
tags:
description: Comma separated list of docker tags to create
type: string

jobs:
generate-jvm-tag:
uses: ./.github/workflows/generate-jvm-tag.yml
with:
jvm-type: ${{ inputs.jvm-type }}
jvm-version: ${{ inputs.jvm-version }}

build-and-push:
name: Build and deploy Java ${{ needs.generate-jvm-tag.outputs.jvm-tag }} OCI image to registry
needs: generate-jvm-tag
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK ${{ inputs.java-build-version }}
uses: actions/setup-java@v4
with:
distribution: ${{ inputs.java-build-distribution }}
java-version: ${{ inputs.java-build-version }}

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Add tags environment variable
if: inputs.tags != ''
run: echo "TAGS=-PdockerTags=${{ inputs.tags }}" >> $GITHUB_ENV

- name: Setup Docker Hub credentials
if: inputs.registry == 'docker.io'
run: |
echo "DOCKER_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" >> $GITHUB_ENV
echo "DOCKER_PASSWORD=${{ secrets.DOCKERHUB_TOKEN }}" >> $GITHUB_ENV
- name: Setup GitHub Container Registry credentials
if: inputs.registry == 'ghcr.io'
run: |
echo "DOCKER_USERNAME=${{ github.actor }}" >> $GITHUB_ENV
echo "DOCKER_PASSWORD=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Build and deploy OCI image
run: >
./gradlew bootBuildImage
-PjvmType=${{ inputs.image-jvm-type }}
-PjdkVersion=${{ inputs.image-jvm-version }}
-PdockerUsername=${{ env.DOCKER_USERNAME }}
-PdockerPassword=${{ env.DOCKER_PASSWORD }}
$TAGS
--imageName=${{ inputs.registry }}/${{ inputs.image-name }}
--publishImage
96 changes: 47 additions & 49 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,60 @@
name: CI
name: Build and test

on:
pull_request:
workflow_dispatch:

env:
DISTRIBUTION: temurin
JVM_TYPE: jre
JVM_VERSION: 17
REGISTRY: ghcr.io

jobs:
create-short-sha:
name: Create short commit sha
build-vars:
name: Create build variables
runs-on: ubuntu-latest
outputs:
short-sha: ${{ steps.short-sha-output.outputs.short-sha }}
distribution: ${{ steps.build-vars.outputs.distribution }}
jvm-type: ${{ steps.build-vars.outputs.jvm-type }}
jvm-version: ${{ steps.build-vars.outputs.jvm-version }}
registry: ${{ steps.build-vars.outputs.registry }}
steps:
- name: Create short commit sha output
id: short-sha-output
run: echo "short-sha=`echo $GITHUB_SHA | cut -c1-8`" >> $GITHUB_OUTPUT
- id: build-vars
name: Create build variables
run: |
echo "distribution=$DISTRIBUTION" >> $GITHUB_OUTPUT
echo "jvm-type=$JVM_TYPE" >> $GITHUB_OUTPUT
echo "jvm-version=$JVM_VERSION" >> $GITHUB_OUTPUT
echo "registry=$REGISTRY" >> $GITHUB_OUTPUT
sha-tag:
name: Create sha docker tag
uses: ./.github/workflows/create-sha-docker-tag.yml
needs: build-vars
with:
jvm-type: ${{ needs.build-vars.outputs.jvm-type }}
jvm-version: ${{ needs.build-vars.outputs.jvm-version }}

build-and-deploy:
name: Build and push Java ${{ matrix.jvmVersion }} ${{ matrix.jvmType }} image to registry
needs: create-short-sha
runs-on: ubuntu-latest
env:
TAG: ${{ needs.create-short-sha.outputs.short-sha }}-${{ matrix.jvmType }}${{ matrix.jvmVersion }}
strategy:
matrix:
jvmType: [jre]
jvmVersion: [17]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Set up JDK ${{ matrix.jvmVersion }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.jvmVersion }}
distribution: temurin
- name: Build and deploy OCI image
run: >
./gradlew bootBuildImage
-PjvmType=${{ matrix.jvmType }}
-PjdkVersion=${{ matrix.jvmVersion }}
-PdockerUsername=${{ github.actor }}
-PdockerPassword=${{ secrets.GITHUB_TOKEN }}
--imageName=$REGISTRY/$GITHUB_REPOSITORY:$TAG
--publishImage
name: Build and deploy OCI image
uses: ./.github/workflows/build-and-deploy-image.yml
needs:
- build-vars
- sha-tag
with:
image-name: ${{ github.repository }}:${{ needs.sha-tag.outputs.tag }}
registry: ${{ needs.build-vars.outputs.registry }}

integration-test:
name: Verify Java ${{ matrix.jvmVersion }} ${{ matrix.jvmType }} image with ${{ matrix.backend }}
name: Verify OCI image with ${{ matrix.backend }}
needs:
- create-short-sha
- build-vars
- build-and-deploy
runs-on: ubuntu-latest
env:
TAG: ${{ needs.create-short-sha.outputs.short-sha }}-${{ matrix.jvmType }}${{ matrix.jvmVersion }}
strategy:
fail-fast: false
matrix:
jvmType: [jre]
jvmVersion: [17]
backend: [
aws-param-store,
aws-s3,
Expand All @@ -78,17 +73,20 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Set up JDK 17

- name: Set up JDK ${{ needs.build-vars.outputs.jvm-version }}
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
distribution: ${{ needs.build-vars.outputs.distribution }}
java-version: ${{ needs.build-vars.outputs.jvm-version }}

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Test with ${{ matrix.backend }}
run: >
./gradlew test -i
-PtestFilter=${{ matrix.backend }}
-PimageRegistry=${{ env.REGISTRY }}
-PimageTag=${{ env.TAG }}
-PjdkVersion=${{ matrix.jvmVersion }}
-PimageRegistry=${{ needs.build-vars.outputs.registry }}
-PjdkVersion=${{ needs.build-vars.outputs.jvm-version }}
-PimageTag=${{ needs.sha-tag.outputs.tag }}
46 changes: 46 additions & 0 deletions .github/workflows/cloud-config-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Find build and latest versions of cloud config

on:
workflow_call:
inputs:
distribution:
description: JVM distribution to run
type: string
default: temurin
java-version:
description: JVM version to run
type: string
default: 17
outputs:
build:
description: Current build version of cloud config
value: ${{ jobs.cloud-config-versions.outputs.build }}
latest:
description: Latest version of cloud config
value: ${{ jobs.cloud-config-versions.outputs.latest }}

jobs:
cloud-config-versions:
name: Create Cloud Config Versions
runs-on: ubuntu-latest
outputs:
build: ${{ steps.vars.outputs.build }}
latest: ${{ steps.vars.outputs.latest }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK ${{ inputs.java-version }}
uses: actions/setup-java@v4
with:
distribution: ${{ inputs.distribution }}
java-version: ${{ inputs.java-version }}

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Set cloud config versions
id: vars
run: |
echo "latest=`curl -s https://search.maven.org/solrsearch/select\?q\=g:%22org.springframework.cloud%22%20AND%20a:%22spring-cloud-config-server%22 | jq -r '.response.docs[0].latestVersion'`" >> $GITHUB_OUTPUT
echo "build=`./gradlew dependencyInsight --dependency org.springframework.cloud:spring-cloud-config-server | grep 'org.springframework.cloud:spring-cloud-config-server:' | tail -1 | cut -d ':' -f 3-`" >> $GITHUB_OUTPUT
35 changes: 35 additions & 0 deletions .github/workflows/create-sha-docker-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Create sha docker tag

on:
workflow_call:
inputs:
jvm-type:
description: JVM type for output image
type: string
default: jre
jvm-version:
description: JVM version for output image
type: string
default: 17
outputs:
tag:
description: Docker tag with sha of commit
value: ${{ jobs.create-sha-docker-tag.outputs.tag }}

jobs:
jvm-tag:
uses: ./.github/workflows/generate-jvm-tag.yml
with:
jvm-type: ${{ inputs.jvm-type }}
jvm-version: ${{ inputs.jvm-version }}

create-sha-docker-tag:
name: Create sha docker tag
needs: jvm-tag
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.vars.outputs.tag }}
steps:
- name: Build sha docker tag
id: vars
run: echo "tag=`echo $GITHUB_SHA | cut -c1-7`-${{ needs.jvm-tag.outputs.jvm-tag }}" >> $GITHUB_OUTPUT
Loading

0 comments on commit d3aa683

Please sign in to comment.