Skip to content

Commit

Permalink
Build and publish Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
juanluisrp committed Jul 19, 2023
1 parent 1c59823 commit f0246a2
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 290 deletions.
Original file line number Diff line number Diff line change
@@ -1,64 +1,69 @@
name: ci

on:
push:
branches:
- '*'
tags:
- 'v*'
pull_request:
branches:
- $default-branch

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
workflow_call:
inputs:
context-path:
description: 'The context used to generate the Docker image'
required: true
type: string
image-name:
description: 'Name of the Docker image. It will appended to the repo name'
required: true
type: string

jobs:
docker_image:
name: 'Build ${{ inputs.image-name }} Docker image'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-${{ inputs.image-name }}
steps:
- name: Checkout
uses: actions/checkout@v3

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

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to GHCR
if: github.event_name != 'pull_request'

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Transform GitHub Actions metadata to Docker image tags
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.vendor=GeoCat B.V.
org.opencontainers.image.vendor=GeoNetwork
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=raw,value={{branch}}-{{sha}},enable=${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Build image
uses: docker/build-push-action@v4
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
file: ./${{ inputs.context-path }}/Dockerfile
build-args: |
MODULE=${{ inputs.context-path }}
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
push: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')}}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


labels: ${{ steps.meta.outputs.labels }}
9 changes: 6 additions & 3 deletions .github/workflows/compile-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
# It also sends the dependency graph to GitHub for further analysis.

name: "Java Compile and Test"
on:
push:
branches: [ $default-branch ]
branches: ['*']
pull_request:
branches: [ $default-branch ]
branches: ['main']
jobs:
compile_and_test:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3

Expand All @@ -18,7 +21,7 @@ jobs:
with:
java-version: '8'
distribution: 'temurin'
cache: maven
cache: 'maven'

- name: Build and test with Maven
run: mvn --batch-mode --update-snapshots verify
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Build docker images of all the services and publish them to ghcr.io in some cases
on:
push:
branches:
- '*'
tags:
- 'v*'
pull_request:
branches:
- main

jobs:
build_docker_images:
permissions:
contents: read
packages: write
strategy:
matrix:
module: [csw-harvester, full-orchestrator, ingester, linkchecker]
uses: ./.github/workflows/build-and-publish-docker-image.yml
with:
context-path: services/${{ matrix.module }}
image-name: ${{ matrix.module }}


7 changes: 0 additions & 7 deletions services/csw-harvester/.github/dependabot.yml

This file was deleted.

64 changes: 0 additions & 64 deletions services/csw-harvester/.github/workflows/docker-images.yml

This file was deleted.

25 changes: 12 additions & 13 deletions services/csw-harvester/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM --platform=$BUILDPLATFORM maven:3-eclipse-temurin-8 as builder

FROM --platform=$BUILDPLATFORM maven:3-eclipse-temurin-8 AS builder

ARG MODULE
WORKDIR /sources
COPY ./ /sources

Expand All @@ -13,32 +13,31 @@ RUN --mount=type=cache,target=/root/.m2/repository \
RUN --mount=type=cache,target=/root/.m2/repository \
mvn -B package -DskipTests
RUN mkdir /application && \
cp target/csw-harvester*.jar /application/csw-harvester.jar
cp $MODULE/target/*.jar /application/application.jar

WORKDIR /application

# Extract spring boot JAR layers
RUN --mount=type=cache,target=/root/.m2/repository \
java -Djarmode=layertools -jar csw-harvester.jar extract

java -Djarmode=layertools -jar application.jar extract

FROM eclipse-temurin:8-jre as finalImage

LABEL vendor="GeoCat B.V."
LABEL org.opencontainers.image.source https://github.com/GeoCat/csw-harvester
FROM eclipse-temurin:8-jre AS finalImage

LABEL vendor="GeoNetwork"
ARG MODULE


# Check the file application.properties for a description of the environment variables that can be customized.
# The property names can be translated to environment varibles passing them to upper case and replacing the dots
# with underscores. For example harvester.jdbc.url -> HARVESTER_JDBC_URL
COPY extra/certs/ /certs
COPY extra/bin /usr/local/bin
COPY $MODULE/extra/certs/ /certs
COPY $MODULE/extra/bin /usr/local/bin

RUN chmod -R +x /usr/local/bin && \
import_certs.sh && \
mkdir -p /opt/csw-harvester
WORKDIR /opt/csw-harvester
import_certs.sh
WORKDIR /opt/$MODULE

COPY --from=builder /application/dependencies/ ./
COPY --from=builder /application/spring-boot-loader ./
COPY --from=builder /application/snapshot-dependencies/ ./
Expand Down
7 changes: 0 additions & 7 deletions services/full-orchestrator/.github/dependabot.yml

This file was deleted.

65 changes: 0 additions & 65 deletions services/full-orchestrator/.github/workflows/docker-images.yml

This file was deleted.

Loading

0 comments on commit f0246a2

Please sign in to comment.