Skip to content

Commit

Permalink
build: New CI Job to make images for docker-hub # (#384)
Browse files Browse the repository at this point in the history
For hyperledger/identus#87
Signed-off-by: FabioPinheiro <[email protected]>
  • Loading branch information
FabioPinheiro authored Nov 26, 2024
1 parent 2873896 commit 5c8a038
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 13 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ jobs:
with:
node-version: "lts/*"

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ env.GITHUB_ACTOR }}
password: ${{ env.GITHUB_TOKEN }}
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ env.GITHUB_ACTOR }}
# password: ${{ env.GITHUB_TOKEN }}

- name: Install Compose
uses: ndeloof/[email protected]
Expand All @@ -73,10 +73,10 @@ jobs:
env:
NODE_OPTIONS: "--openssl-legacy-provider"
run: |
sbt -mem 2048 -J-Xmx5120m docker:publishLocal
MEDIATOR_VERSION=$(cut version.sbt -d '=' -f2 | tr -d '" ')
echo "MEDIATOR_VERSION=${MEDIATOR_VERSION}" >> $GITHUB_ENV
echo ${MEDIATOR_VERSION}
sbt -mem 2048 -J-Xmx5120m "set ThisBuild / version := \"tmp\"" docker:publishLocal
# MEDIATOR_VERSION=$(cut version.sbt -d '=' -f2 | tr -d '" ')
# echo "MEDIATOR_VERSION=${MEDIATOR_VERSION}" >> $GITHUB_ENV
# echo ${MEDIATOR_VERSION}
- name: Start Mediator
uses: isbang/[email protected]
with:
Expand Down
161 changes: 161 additions & 0 deletions .github/workflows/release-docker-hub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
name: Release to Docker Hub
# ower: FabioPinheiro
# updated: 2024/11/25
# How to test:
# > git tag v9.9.9
# > act --artifact-server-path /tmp/artifacts -s GITHUB_TOKEN="$(gh auth token)" --var DOCKERHUB_FMGP_USERNAME=$DOCKERHUB_FMGP_USERNAME -s DOCKERHUB_FMGP_TOKEN=$DOCKERHUB_FMGP_TOKEN --var DOCKERHUB_IDENTUS_USERNAME=$DOCKERHUB_IDENTUS_USERNAME -s DOCKERHUB_IDENTUS_TOKEN=$DOCKERHUB_IDENTUS_TOKEN -j build-and-push-docker-images schedule
# > git tag --delete v9.9.9

concurrency:
group: release

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Run every day at midnight UTC
push:
tags:
- v*

permissions:
contents: read

jobs:
build-binaries:
if: ${{ !contains(github.event.head_commit.message, 'chore(release)') }}
runs-on: ubuntu-latest
env:
GITHUB_ACTOR: "hyperledger-bot"
GITHUB_ACTOR_EMAIL: "[email protected]"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true
SBT_OPTS: -Xmx2G
steps:
- uses: actions/checkout@v4

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v14
with:
java-version: [email protected]

- name: Cache sbt
uses: coursier/[email protected]

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"

- name: Build Binaries
env:
NODE_OPTIONS: --openssl-legacy-provider
run: sbt -J-Xmx5120m "docker:stage"

- name: Save build Directory
uses: actions/upload-artifact@v4
with:
name: docker-directory-artifact
path: ./mediator/target/docker/stage


build-and-push-docker-images:
name: Build and Push Docker images
runs-on: ubuntu-latest
needs: build-binaries
strategy:
fail-fast: false
matrix:
docker:
- # identus # This is a test account
registry: docker.io
repository: ${{vars.DOCKERHUB_IDENTUS_USERNAME}}
username: ${{vars.DOCKERHUB_IDENTUS_USERNAME}}
password_name: DOCKERHUB_IDENTUS_TOKEN
tags_noschedule: |
type=semver,pattern={{version}}
type=raw,value=latest,enable={{is_default_branch}}
# type=raw,value=${{needs.pick-build-version.outputs.build_version}}
tags_schedule: |
type=schedule,pattern=nightly,enable={{is_default_branch}}
- # fmgp # My presonal acount also for testing
registry: docker.io
repository: ${{vars.DOCKERHUB_FMGP_USERNAME}}
username: ${{vars.DOCKERHUB_FMGP_USERNAME}}
password_name: DOCKERHUB_FMGP_TOKEN
tags_noschedule: |
type=semver,pattern={{version}},enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
tags_schedule: |
type=schedule,enable={{is_default_branch}}
steps:
- name: Set test variable
run: |
echo "META_CONFIG<<EOF" >> $GITHUB_ENV
if [ ${{ github.event_name }} == 'schedule' ]; then
echo "${{matrix.docker.tags_schedule}}" >> $GITHUB_ENV;
# type=semver,pattern={{version}}
# type=sha,prefix={{branch}}-
else
echo "${{matrix.docker.tags_noschedule}}" >> $GITHUB_ENV;
# type=schedule,pattern={{date 'YYYYMMDD'}}
fi
echo "EOF" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ matrix.docker.registry }}/${{ matrix.docker.repository }}/identus-mediator
tags: "${{ env.META_CONFIG }}"

- name: JOB INFO
run: |
echo "##################"
echo "#### JOB INFO ####"
echo "##################"
echo "### github.event_name=${{github.event_name}} (Is this type 'schedule'""? ${{ github.event_name == 'schedule' }})"
echo "### matrix.docker.tags_schedule: ${{ matrix.docker.tags_schedule }}"
echo "### matrix.docker.tags_noschedule: ${{ matrix.docker.tags_noschedule }}"
echo "### env.META_CONFIG: ${{ env.META_CONFIG }}"
echo "### TAGS: ${{ steps.meta.outputs.tags == '' }}"
echo "${{ steps.meta.outputs.tags }}"
echo "### runner: ${{ toJSON(runner) }}"
echo "### github: ${{ toJSON(github) }}"
- name: Download docker-directory-artifact
uses: actions/download-artifact@v4
with:
name: docker-directory-artifact
path: docker-artifact

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
buildkitd-config-inline: |
[worker.oci]
max-parallelism = 1
platforms: linux/amd64,linux/arm64

- name: Login to the ${{ matrix.docker.registry }} Container Registry with ${{ matrix.docker.username }}
uses: docker/login-action@v3
with:
registry: ${{ matrix.docker.registry }}
username: ${{ matrix.docker.username }}
password: ${{ secrets[matrix.docker.password_name] }}

# TODO FIX These builds the image multiple times (matrix)
- name: Build and push identus-mediator Image
id: push
uses: docker/build-push-action@v6
with:
context: ./docker-artifact/
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
push: ${{ steps.meta.outputs.tags != '' }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ resolvers ++= Resolver.sonatypeOssRepos("snapshots")
inThisBuild(
Seq(
scalaVersion := "3.3.3", // Also update docs/publishWebsite.sh and any ref to scala-3.3.3
versionScheme := Some("semver-spec"), // https://www.scala-sbt.org/1.x/docs/Publishing.html#Version+scheme
)
)

Expand Down Expand Up @@ -172,7 +173,7 @@ lazy val scalaJSBundlerConfigure: Project => Project =
// Compile / fullOptJS / webpackExtraArgs += "--mode=production",
Compile / fastOptJS / webpackDevServerExtraArgs += "--mode=development",
Compile / fullOptJS / webpackDevServerExtraArgs += "--mode=production",
useYarn := true
// useYarn := true
)

lazy val buildInfoConfigure: Project => Project = _.enablePlugins(BuildInfoPlugin)
Expand Down
7 changes: 6 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,20 @@ addSbtPlugin("com.github.sbt" % "sbt-release" % "1.4.0")

// Github Packages
if (sys.env.get("GITHUB_TOKEN").isDefined) {
println(s"Adding plugin sbt-dependency-tree since env GITHUB_TOKEN is defined.")
// The reason for this is that the plugin needs the variable to be defined. We don't want to have that requirement.
libraryDependencies += {
val log = sLog.value
log.info(s"Adding plugin sbt-dependency-tree since env GITHUB_TOKEN is defined.")

val dependency = "com.codecommit" % "sbt-github-packages" % "0.5.3"
val sbtV = (pluginCrossBuild / sbtBinaryVersion).value
val scalaV = (update / scalaBinaryVersion).value
Defaults.sbtPluginExtra(dependency, sbtV, scalaV)
}
} else libraryDependencies ++= Seq[ModuleID]()

// PUBLISH
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.0")

// Native Packager
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.10.0")
1 change: 0 additions & 1 deletion version.sbt

This file was deleted.

0 comments on commit 5c8a038

Please sign in to comment.