Skip to content

Commit

Permalink
Remove publish to dockerhub, support image and directory name mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHess committed Sep 25, 2024
1 parent 95e050a commit fd082e0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 35 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/build_config_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,14 @@ jobs:
- uses: actions/checkout@v4

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

- name: Login to private container registry
if: ${{ github.event_name == 'pull_request' }}
- name: Login to container registry
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 }}
11 changes: 2 additions & 9 deletions .github/workflows/build_eureka_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,14 @@ jobs:
- uses: actions/checkout@v4

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

- name: Login to private container registry
if: ${{ github.event_name == 'pull_request' }}
- name: Login to container registry
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 }}
11 changes: 2 additions & 9 deletions .github/workflows/build_springboot_admin_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,14 @@ jobs:
- uses: actions/checkout@v4

- name: Build Image
run: ./build.ps1 -Name ${{ env.IMAGE_NAME }} -Registry ${{ env.REGISTRY }}
run: ./build.ps1 -Name ${{ env.IMAGE_NAME }} -Registry ${{ env.REGISTRY }} -DirectoryName "spring-boot-admin"

- name: Login to private container registry
if: ${{ github.event_name == 'pull_request' }}
- name: Login to container registry
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 }}
23 changes: 15 additions & 8 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
.PARAMETER Registry
Set the container registry. Defaults to dockerhub under steeltoeoss.
.PARAMETER DirectoryName
Name of directory holding files that define the image. Defaults to the same value used for "Name".
#>

# -----------------------------------------------------------------------------
Expand All @@ -45,7 +48,8 @@ param (
[Switch] $List,
[String] $Name,
[String] $Tag,
[String] $Registry
[String] $Registry,
[String] $DirectoryName
)

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -85,13 +89,16 @@ if (!$Name)
throw "Name not specified; run with -Help for help"
}

$ImageDirectory = Join-Path $ImagesDirectory $Name
if (!(Test-Path $ImageDirectory))
if (!$DirectoryName)
{
throw "Unknown image $Name; run with -List to list available images"
$DirectoryName = $Name
}

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

if (!(Get-Command "docker" -ErrorAction SilentlyContinue))
{
Expand All @@ -101,7 +108,7 @@ if (!(Get-Command "docker" -ErrorAction SilentlyContinue))
$Dockerfile = Join-Path $ImageDirectory Dockerfile
if (!(Test-Path $Dockerfile))
{
throw "No Dockerfile for $Name (expected $Dockerfile)"
throw "No Dockerfile for $DirectoryName (expected $Dockerfile)"
}

if (!$Tag)
Expand All @@ -116,11 +123,11 @@ if (!$Tag)
{
$Tag += "-$Revision"
}
$Tag += " $(Get-Content $ImageDirectory/metadata/ADDITIONAL_TAGS | ForEach { $_.replace("$Name","$DockerOrg/$Name") })"
$Tag += " $(Get-Content $ImageDirectory/metadata/ADDITIONAL_TAGS | ForEach-Object { $_.replace("$DirectoryName","$DockerOrg/$Name") })"
}
else
{
throw "No metadata found for $Name"
throw "No metadata found for $DirectoryName"
}
}

Expand Down

0 comments on commit fd082e0

Please sign in to comment.