Code Monkey home page Code Monkey logo

portable-mvn-repo's Introduction

POC for Blessed Maven Repo

In this POC, we use Maven and Snyk to showcase how to create a blessed repo that can be reused across projects.

Pre-requisites

  • Java SDK
  • Maven
  • Snyk account

Files

Dockerfile

Defines a Docker image containing a Maven repo with artifacts defined by the dependency tree generated for pom.xml.

pom.xml

Declares all high-level dependencies to be consumed later.

nginx.conf

Configuration for the HTTP service exposing the Maven repo endpoint. Listens to port 80 by default.

test-project-good

Example of a project that can consumes the dependencies from the local repo gracefully.

test-project-bad

Example of a project that can consumes a non-approved dependency, i.e. not present in the local repo.

test-project-good(bad)/pom.xml

Example of a pom.xml that uses the local repo as the only source to download dependencies. One of the dependencies differ in

Run it

Step 1: Build the blessed repo

export SNYK_API_TOKEN=(your token goes here)
docker build --build-arg SNYK_API_TOKEN -t snyked-maven-repo .

Step 2: Run the repo service locally

docker run -p 8080:80 --rm snyked-maven-repo:latest

Step 3: Test the good example

rm -rf ~/.m2; rm -rf test-project-good/target; mvn install -f test-project-good/pom.xml

Notice that all downloaded files are coming from http://localhost:8080

Step 4: Test the bad examples

rm -rf ~/.m2; rm -rf test-project-bad/target; mvn install -f test-project-bad/pom.xml
rm -rf ~/.m2; rm -rf test-project-bad2/target; mvn install -f test-project-bad2/pom.xml

Notice that all downloaded files are coming from http://localhost:8080 and there is an error due to an unresolved dependency.

The Good

  • Creating a blessed repo is possible and it can be deployed in organizations that have tight control on dependency management or restrict network access in some environments.

The Bad

  • This solution does not work if developer has non-blessed dependencies cached locally. For this reason, we delete the local Maven cache in the commands above. This limits how much proxying the download of the dependencies can be valuable to developers but it can still be useful in a CI/CD pipeline where the cache is always clean in the beginning.

The Ugly

  • This time-boxed solution does not allow multiple versions of the same artifact to be available in the repo. On the other hand, this can be resolved by enhancing this POC:
    • Developer declares dependencies in a separate file: dependencies.txt or something.
    • Dockerfile has instructions to read that file and generate one pom.xml per dependency and resolve it. Cache is maintained between runs, so all the dependencies are cached.

portable-mvn-repo's People

Contributors

artursouza avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.