Skip to content

Commit

Permalink
Merge pull request #522 from gounthar/fix-docker
Browse files Browse the repository at this point in the history
chore(ga): Fix Docker build and integrate into release process
  • Loading branch information
jonesbusy authored Dec 30, 2024
2 parents 53a85fc + 9684939 commit 9fcfba1
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 156 deletions.
94 changes: 87 additions & 7 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
RELEASE_DRAFT_BODY: ${{ steps.draft.outputs.body }}

release:
outputs:
version: ${{ steps.extract-version.outputs.version }}
runs-on: ubuntu-latest
needs: [validate]
if: needs.validate.outputs.should_release == 'true'
Expand All @@ -61,11 +63,11 @@ jobs:
# https://github.com/jenkins-infra/github-reusable-workflows/issues/36
- name: Set up Maven
run: |
wget --no-verbose https://dlcdn.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz
echo $CHECKSUM apache-maven-$MAVEN_VERSION-bin.tar.gz | sha512sum --check
tar xzf apache-maven-$MAVEN_VERSION-bin.tar.gz
rm apache-maven-$MAVEN_VERSION-bin.tar.gz
sudo mv apache-maven-$MAVEN_VERSION /opt/maven
wget --no-verbose "https://dlcdn.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz"
echo "$CHECKSUM" "apache-maven-$MAVEN_VERSION-bin.tar.gz" | sha512sum --check
tar xzf "apache-maven-$MAVEN_VERSION-bin.tar.gz"
rm "apache-maven-$MAVEN_VERSION-bin.tar.gz"
sudo mv "apache-maven-$MAVEN_VERSION" /opt/maven
sudo rm -f /usr/bin/mvn
sudo ln -s /opt/maven/bin/mvn /usr/bin/mvn
mvn --version
Expand All @@ -84,9 +86,9 @@ jobs:
- name: Extract version
id: extract-version
run: |
VERSION=$(mvn -q -Dset.changelist -Dignore.dirt -DforceStdout org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.version)
VERSION="$(mvn -q -Dset.changelist -Dignore.dirt -DforceStdout org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.version)"
echo "VERSION=$VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Attach jar to release
with:
Expand Down Expand Up @@ -122,3 +124,81 @@ jobs:
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
- name: Upload built jar
uses: actions/upload-artifact@v4
with:
name: built-jar
retention-days: 1
path: |
plugin-modernizer-cli/target/jenkins-plugin-modernizer-${{ steps.extract-version.outputs.version }}.jar
plugin-modernizer-core/target/plugin-modernizer-core-${{ steps.extract-version.outputs.version }}.jar
docker:
runs-on: ubuntu-latest
needs: [release]
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
# Required: Free up ~6GB for Docker build
with:
# this might remove tools that are actually needed,
# when set to "true" but frees about 6 GB
tool-cache: true
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
swap-storage: true

- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download built jar
uses: actions/download-artifact@v4
with:
name: built-jar
path: . # Explicitly set to root to match Dockerfile COPY paths

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

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

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

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=${{ needs.release.outputs.version }}
type=raw,value=latest
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: ${{ vars.DOCKER_PLATFORMS || 'linux/amd64,linux/arm64' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max,keep-days=30
provenance: true
sbom: true
build-args: |
MAVEN_CACHE=.m2
VERSION=${{ needs.release.outputs.version }}
114 changes: 0 additions & 114 deletions .github/workflows/github-docker-registry-push.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/lint-workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint Workflows

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Lint GitHub Actions workflows
uses: super-linter/[email protected]
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_GITHUB_ACTIONS: true
# To report GitHub Actions status checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40 changes: 5 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,7 @@
# Define the VERSION argument with a default value
ARG VERSION=999999-SNAPSHOT

# First stage: Build the project using Maven and Eclipse Temurin JDK 21
FROM maven:3.9.9-eclipse-temurin-21-jammy AS builder

# Re-define the VERSION argument for the builder stage
ARG VERSION

# Set the VERSION environment variable
ENV VERSION=${VERSION}


# Add the current directory to the /plugin-modernizer directory in the container
ADD . /plugin-modernizer
RUN mkdir -p /plugin-modernizer
WORKDIR /plugin-modernizer

# Define a build argument for the Maven cache location
ARG MAVEN_CACHE=.m2
ADD ${MAVEN_CACHE} /root/.m2

# Print the Maven local repository path
RUN echo "Maven local repository path: $(mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)"

# List the Maven cache directory itself
RUN ls -ld $(mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)

# Ensure the Maven cache directory is writable
RUN chmod -R 777 $(mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)

RUN cd /plugin-modernizer && \
mvn clean install -DskipTests

# Second stage: Create the final image using Maven and Eclipse Temurin JDK 21
# Create the image using Maven and Eclipse Temurin JDK 21
FROM maven:3.9.9-eclipse-temurin-21-jammy AS result-image

LABEL org.opencontainers.image.description="Using OpenRewrite Recipes for Plugin Modernization or Automation Plugin Build Metadata Updates"
Expand Down Expand Up @@ -66,9 +35,10 @@ ARG VERSION
# Set the VERSION environment variable
ENV VERSION=${VERSION}

# Copy the built JAR files from the builder stage to the final image
COPY --from=builder /plugin-modernizer/plugin-modernizer-cli/target/jenkins-plugin-modernizer-${VERSION}.jar /jenkins-plugin-modernizer.jar
COPY --from=builder /plugin-modernizer/plugin-modernizer-core/target/plugin-modernizer-core-${VERSION}.jar /jenkins-plugin-modernizer-core.jar
# Copy the built JAR files from the downloaded artifacts to the final image
# Fail fast if jars are missing
COPY --chmod=755 plugin-modernizer-cli/target/jenkins-plugin-modernizer-${VERSION}.jar /jenkins-plugin-modernizer.jar
COPY --chmod=755 plugin-modernizer-core/target/plugin-modernizer-core-${VERSION}.jar /jenkins-plugin-modernizer-core.jar

# Install the core dependency using the Maven install plugin
RUN mvn org.apache.maven.plugins:maven-install-plugin:${MVN_INSTALL_PLUGIN_VERSION}:install-file \
Expand Down

0 comments on commit 9fcfba1

Please sign in to comment.