Skip to content

Commit

Permalink
update config & eureka servers, align dockerfiles and add GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHess committed Feb 22, 2024
1 parent bb138ee commit b927d0d
Show file tree
Hide file tree
Showing 29 changed files with 279 additions and 445 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build_config_server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build Config Server

on:
pull_request:
branches:
- main
paths:
- 'config-server/**'
push:
branches:
- main
paths:
- 'config-server/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: 'read'

env:
IMAGE_NAME: config-server
REGISTRY: ${{ github.event_name == 'pull_request' && vars.DOCKER_REGISTRY || 'steeltoeoss' }}

jobs:
build-push:
name: Build and push image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build Image
run: ./build.ps1 -Name ${{ env.IMAGE_NAME }} -Registry ${{ env.REGISTRY }}

- name: Login to private container registry
if: ${{ github.event_name == 'pull_request' }}
uses: docker/login-action@v3
with:
registry: "${{ vars.DOCKER_REGISTRY }}"
username: "${{ secrets.DOCKER_USERNAME }}"
password: "${{ secrets.DOCKER_PASSWORD }}"


- name: Login to Docker Hub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push image
run: docker push --all-tags ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
53 changes: 53 additions & 0 deletions .github/workflows/build_eureka_server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build Eureka Server

on:
pull_request:
branches:
- main
paths:
- 'eureka-server/**'
push:
branches:
- main
paths:
- 'eureka-server/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: 'read'

env:
IMAGE_NAME: eureka-server
REGISTRY: ${{ github.event_name == 'pull_request' && vars.DOCKER_REGISTRY || 'steeltoeoss' }}

jobs:
build-push:
name: Build and push image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build Image
run: ./build.ps1 -Name ${{ env.IMAGE_NAME }} -Registry ${{ env.REGISTRY }}

- name: Login to private container registry
if: ${{ github.event_name == 'pull_request' }}
uses: docker/login-action@v3
with:
registry: "${{ vars.DOCKER_REGISTRY }}"
username: "${{ secrets.DOCKER_USERNAME }}"
password: "${{ secrets.DOCKER_PASSWORD }}"


- name: Login to Docker Hub
if: ${{ github.event_name != 'pull_request' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push image
run: docker push --all-tags ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
12 changes: 12 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,15 @@ $ manifest-tool --username * --password * push from-spec config-server/manifest.
| CloudFoundry UAA Server

|===

== Debug Image Building

Via link:StackOverflow[https://stackoverflow.com/questions/32353055/how-to-start-a-stopped-docker-container-with-a-different-command/39329138#39329138] - Here are the commands to list files in a stopped container.

1. Find the id of the stopped container
* `docker ps -a`
2. Commit the stopped container to a new image: test_image.
* `docker commit $CONTAINER_ID test_image`
3. Run the new image in a new container with a shell.
* `docker run -ti --entrypoint=sh test_image`

90 changes: 64 additions & 26 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,77 +31,115 @@
.PARAMETER Tag
Override the image tag.
.PARAMETER Registry
Set the container registry. Defaults to dockerhub under steeltoeoss.
#>

# -----------------------------------------------------------------------------
# args
# -----------------------------------------------------------------------------

param(
param (
[Switch] $Help,
[Switch] $List,
[String] $Name,
[String] $Tag
[String] $Tag,
[String] $Registry
)

$DockerOrg = "steeltoeoss"
$DockerArch = "amd64"
$DockerOs = "linux"

# -----------------------------------------------------------------------------
# impl
# -----------------------------------------------------------------------------

if ($Help) {
if ($Registry)
{
$DockerOrg = $Registry
}
else
{
$DockerOrg = "steeltoeoss"
}

if ($Help)
{
Get-Help $PSCommandPath -Detailed
return
}

if ($Name -And $List) {
if ($Name -And $List)
{
throw "-Name and -List are mutually exclusive"
}

$ImagesDirectory = Split-Path -Parent $PSCommandPath

if ($List) {
Get-Childitem -Path $ImagesDirectory -Directory | Select-Object Name
if ($List)
{
Get-Childitem -Path $ImagesDirectory -Directory | Where-Object { !$_.Name.StartsWith(".") } | Select-Object Name
return
}

if (!$Name) {
if (!$Name)
{
throw "Name not specified; run with -Help for help"
}

$ImageDirectory = Join-Path $ImagesDirectory $Name
if (!(Test-Path $ImageDirectory)) {
if (!(Test-Path $ImageDirectory))
{
throw "Unknown image $Name; run with -List to list available images"
}
$Name =Split-Path -Leaf $ImageDirectory # this removes stuff like ".\" prefix

if (!(Get-Command "docker" -ErrorAction SilentlyContinue)) {
$Name = Split-Path -Leaf $ImageDirectory # this removes stuff like ".\" prefix

if (!(Get-Command "docker" -ErrorAction SilentlyContinue))
{
throw "'docker' command not found"
}

$Dockerfile = Join-Path $ImageDirectory Dockerfile

if (!(Test-Path $Dockerfile)) {
throw "No Dockerfile for $Image (expected $Dockerfile)"
if (!(Test-Path $Dockerfile))
{
throw "No Dockerfile for $Name (expected $Dockerfile)"
}

if (!$Tag) {
$Tag = "$DockerOrg/$Name-$DockerArch-$DockerOS"
$VersionMatcher = Select-String -Path $Dockerfile -Pattern '^ENV\s+IMAGE_VERSION\s*=?\s*(.+)$'
if ($VersionMatcher) {
$Version = $VersionMatcher.Matches.Groups[1]
if (!$Tag)
{
if (Test-Path "$ImageDirectory/metadata")
{
$Tag = "-t $DockerOrg/$Name"
$Version = Get-Content "$ImageDirectory/metadata/IMAGE_VERSION"
$Tag += ":$Version"
$RevisionMatcher = Select-String -Path $Dockerfile -Pattern '^ENV\s+IMAGE_REVISION\s*=?\s*(.+)$'
if ($RevisionMatcher) {
$Revision = $RevisionMatcher.Matches.Groups[1]
$Revision = Get-Content "$ImageDirectory/metadata/IMAGE_REVISION"
if ($Revision)
{
$Tag += "-$Revision"
}
$Tag += " $(Get-Content $ImageDirectory/metadata/ADDITIONAL_TAGS | ForEach { $_.replace("$Name","$DockerOrg/$Name") })"
}
else
{
$DockerArch = "amd64"
$DockerOs = "linux"
$Tag = "-t $DockerOrg/$Name-$DockerArch-$DockerOS"
$VersionMatcher = Select-String -Path $Dockerfile -Pattern '^ENV\s+IMAGE_VERSION\s*=?\s*(.+)$'
if ($VersionMatcher)
{
$Version = $VersionMatcher.Matches.Groups[1]
$Tag += ":$Version"
$RevisionMatcher = Select-String -Path $Dockerfile -Pattern '^ENV\s+IMAGE_REVISION\s*=?\s*(.+)$'
if ($RevisionMatcher)
{
$Revision = $RevisionMatcher.Matches.Groups[1]
$Tag += "-$Revision"
}
}
}
}

docker build -t $Tag $ImageDirectory
$docker_command = "docker build $Tag $ImageDirectory"
Write-host $docker_command
#Invoke-Expression $docker_command

# vim: et sw=4 sts=4
21 changes: 13 additions & 8 deletions config-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
# Spring Config Server Build
# -----------------------------------------------------------------------------

FROM bellsoft/liberica-openjdk-alpine:11 as build
FROM eclipse-temurin:21-alpine as build
WORKDIR /scratch
RUN apk add httpie
RUN apk add patch
RUN http https://start.spring.io/starter.zip \
type==gradle-project \
platformVersion==2.3.3.RELEASE \
jvmVersion==11 \
platformVersion==3.2.2 \
jvmVersion==21 \
groupId==io.steeltoe.docker \
artifactId==configserver \
applicationName==ConfigServer \
dependencies==cloud-config-server \
language==java \
dependencies==cloud-config-server,actuator \
--output configserver.zip
RUN mkdir configserver && unzip -d configserver configserver.zip
COPY patches patches
Expand All @@ -23,15 +25,18 @@ RUN for patch in patches/*.patch; do \
cd ..; \
done
RUN configserver/gradlew bootJar --project-dir configserver --no-daemon
COPY metadata metadata

# -----------------------------------------------------------------------------
# Spring Config Server Linux Image
# -----------------------------------------------------------------------------

FROM bellsoft/liberica-openjdk-alpine:11
ENV IMAGE_VERSION 2.2.5
# ENV IMAGE_REVISION r1
FROM eclipse-temurin:21
RUN export IMAGE_VERSION=$(cat metadata/IMAGE_VERSION)
RUN export IMAGE_REVISION=$(cat metadata/IMAGE_REVISION)
RUN export JAR_FILE="configserver-$IMAGE_VERSION.jar"
ENV SERVER_PORT=8888
WORKDIR /config-server
COPY --from=build /scratch/configserver/build/libs .
EXPOSE 8888
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "configserver-2.2.5.jar"]
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", $JAR_FILE]
1 change: 1 addition & 0 deletions config-server/metadata/ADDITIONAL_TAGS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-t config-server:4.1 -t config-server:4 -t config-server:latest
Empty file.
1 change: 1 addition & 0 deletions config-server/metadata/IMAGE_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.1.0
12 changes: 6 additions & 6 deletions config-server/patches/enableconfigserver.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- a/src/main/java/io/steeltoe/docker/configserver/ConfigServer.java 2020-09-14 16:02:18.000000000 -0400
+++ b/src/main/java/io/steeltoe/docker/configserver/ConfigServer.java 2020-09-15 06:45:08.000000000 -0400
--- configserver/src/main/java/io/steeltoe/docker/configserver/ConfigServer.java 2024-02-21 13:33:04.000000000 -0600
+++ configserver/src/main/java/io/steeltoe/docker/configserver/ConfigServer.java 2024-02-21 13:40:40.622446300 -0600
@@ -1,12 +1,21 @@
package io.steeltoe.docker.configserver;

Expand All @@ -13,12 +13,12 @@
+@EnableConfigServer
public class ConfigServer {

+ private static final Logger logger = LoggerFactory.getLogger(ConfigServer.class);
+ private static final Logger logger = LoggerFactory.getLogger(ConfigServer.class);
+
public static void main(String[] args) {
+ System.setProperty("spring.config.name", "configserver");
+ Package pkg = EnableConfigServer.class.getPackage();
+ logger.info("{} {} by {}", pkg.getImplementationTitle(), pkg.getImplementationVersion(), pkg.getImplementationVendor());
+ System.setProperty("spring.config.name", "configserver");
+ Package pkg = EnableConfigServer.class.getPackage();
+ logger.info("{} {} by {}", pkg.getImplementationTitle(), pkg.getImplementationVersion(), pkg.getImplementationVendor());
SpringApplication.run(ConfigServer.class, args);
}

10 changes: 5 additions & 5 deletions config-server/patches/version.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--- a/build.gradle 2020-09-14 16:02:18.000000000 -0400
+++ b/build.gradle 2020-09-14 16:27:55.000000000 -0400
--- configserver/build.gradle 2024-02-21 09:39:40.000000000 -0600
+++ configserver/build.gradle 2024-02-21 11:03:17.615054116 -0600
@@ -5,7 +5,7 @@
}

group = 'io.steeltoe.docker'
-version = '0.0.1-SNAPSHOT'
+version = '2.2.5'
sourceCompatibility = '11'
+version = '4.1.0'

repositories {
java {
sourceCompatibility = '17'
Loading

0 comments on commit b927d0d

Please sign in to comment.