Skip to content

Commit

Permalink
Merge branch 'jenkinsci:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
gounthar authored Sep 24, 2024
2 parents 8d92da7 + c4899e1 commit f637964
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 31 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/github-docker-registry-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,29 @@ jobs:
packages: write

steps:
# Check if the pull request is from a forked repository
- name: Check if PR is from a fork
run: echo "IS_FORK=$(if [ '${{ github.event.pull_request.head.repo.full_name }}' != '${{ github.repository }}' ]; then echo 'true'; else echo 'false'; fi)" >> $GITHUB_ENV

# Checkout the repository
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# Set up Java environment
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'

# Resolve Maven cache path
- name: Resolve Maven cache path
run: echo "MAVEN_CACHE_PATH=$(realpath ~/.m2/repository)" >> $GITHUB_ENV

# Cache Maven dependencies
- name: Cache Maven dependencies
uses: actions/cache@v3
with:
Expand All @@ -50,45 +55,44 @@ jobs:
restore-keys: |
${{ runner.os }}-maven-
# Build the project with Maven and install dependencies in the Docker context
- name: Build with Maven and install dependencies in the Docker context
run: mvn clean install && cp -vraxu ~/.m2 .m2
env:
MAVEN_CACHE: ${{ env.MAVEN_CACHE_PATH }}

# Set up QEMU for multi-platform builds
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

# Set up Docker Buildx for building multi-platform images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Login to GitHub Container Registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image to GitHub Container Registry
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
MAVEN_CACHE=.m2
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
show-summary: true
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ RUN cd /plugin-modernizer && \
# Second stage: Create the final image using Maven and Eclipse Temurin JDK 21
FROM maven:3.9.9-eclipse-temurin-21 AS result-image

LABEL org.opencontainers.image.description="Using OpenRewrite Recipes for Plugin Modernization or Automation Plugin Build Metadata Updates"

# Update package lists and install necessary packages
RUN apt-get update && \
apt-get install -y curl zip unzip && \
Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,41 @@ See example generated files:

More about [Openrewrite Data Tables](https://docs.openrewrite.org/running-recipes/data-tables)

## Running with Docker

You can use the Docker image supplied by this project to run the Plugin Modernizer Tool without needing to install Java or Maven on your local machine.

### Prerequisites

- Docker installed on your machine.
- A GitHub token with the necessary scopes.
- A file named `plugins.txt` containing the list of plugins.

Of course, you don't need a `plugins.txt` file if you are using the `--plugins` option.

### Example
Below is an example of how to use the Docker image with a local `plugins.txt` file.

```shell
docker run \
-e GH_TOKEN=${GH_TOKEN} \
-e GH_OWNER=${GH_OWNER} \
-v $(pwd)/plugins.txt:/plugins.txt \
ghcr.io/jenkinsci/plugin-modernizer-tool:main \
--plugin-file /plugins.txt --recipes AddPluginsBom,AddCodeOwner
```

### Explanation

- `-e GH_TOKEN=${GH_TOKEN}`: Passes the GitHub token as an environment variable.
- `-e GH_OWNER=${GH_OWNER}`: Passes the GitHub owner as an environment variable.
- `-v $(pwd)/plugins.txt:/plugins.txt`: Mounts the plugins.txt file from the current directory to the Docker container.
- `ghcr.io/jenkinsci/plugin-modernizer-tool:main`: Specifies the Docker image to use.
- `--plugin-file /plugins.txt`: Specifies the path to the plugin file inside the Docker container.
- `--recipes AddPluginsBom,AddCodeOwner`: Specifies the recipes to apply.

This command will run the Plugin Modernizer Tool inside the Docker container using the specified environment variables and plugin file.

## Reproducibility

The maven build should be reproducible
Expand Down
3 changes: 2 additions & 1 deletion scripts/import-maven-cache-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ echo "Maven local repository path determined: $MAVEN_REPO"

# Copy the Maven repository to the current directory.
echo "Copying Maven repository to the current directory..."
cp -r "$MAVEN_REPO" .m2
mkdir -p .m2/repository
rsync -avxu "$MAVEN_REPO/" .m2/repository

# Verify the copy operation.
if [ $? -eq 0 ]; then
Expand Down
42 changes: 21 additions & 21 deletions scripts/import-maven-cache.bat
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
@echo off
REM This script copies the Maven local repository to the current directory.
# This script copies the Maven local repository to the current directory.

echo Determining Maven local repository path...
Write-Output "Determining Maven local repository path..."

REM Get the Maven local repository path using Maven's help:evaluate goal.
for /f "delims=" %%i in ('mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout') do set MAVEN_REPO=%%i
# Get the Maven local repository path using Maven's help:evaluate goal.
$mavenRepo = mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout

REM Check if the Maven repository path was found.
if "%MAVEN_REPO%"=="" (
echo Failed to determine Maven local repository path.
exit /b 1
)
# Check if the Maven repository path was found.
if (-not $mavenRepo) {
Write-Output "Failed to determine Maven local repository path."
exit 1
}

echo Maven local repository path determined: %MAVEN_REPO%
Write-Output "Maven local repository path determined: $mavenRepo"

REM Copy the Maven repository to the current directory.
echo Copying Maven repository to the current directory...
xcopy /E /I "%MAVEN_REPO%" ".m2"
# Copy the Maven repository to the current directory.
Write-Output "Copying Maven repository to the current directory..."
New-Item -ItemType Directory -Path .m2\repository -Force
Copy-Item -Recurse -Force "$mavenRepo\*" .m2\repository

REM Verify the copy operation.
if %errorlevel%==0 (
echo Maven repository copied successfully to .m2
) else (
echo Failed to copy Maven repository.
exit /b 1
)
# Verify the copy operation.
if ($?) {
Write-Output "Maven repository copied successfully to .m2"
} else {
Write-Output "Failed to copy Maven repository."
exit 1
}
3 changes: 2 additions & 1 deletion scripts/import-maven-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ echo "Maven local repository path determined: $MAVEN_REPO"

# Copy the Maven repository to the current directory.
echo "Copying Maven repository to the current directory..."
cp -r "$MAVEN_REPO" .m2
mkdir -p .m2/repository
cp -vraxu "$MAVEN_REPO" .m2/repository

# Verify the copy operation.
if [ $? -eq 0 ]; then
Expand Down

0 comments on commit f637964

Please sign in to comment.