Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ehsaniara/maven-repository-aws-s3

Make AWS S3 Bucket as your private maven repository
https://github.com/ehsaniara/maven-repository-aws-s3

aws aws-s3 iam-users java java11 maven-plugin maven-repository oss plugin s3

Last synced: 2 days ago
JSON representation

Make AWS S3 Bucket as your private maven repository

Awesome Lists containing this project

README

        

# maven-repository-aws-s3

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.ehsaniara/maven-repository-aws-s3.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.ehsaniara%22%20AND%20a:%22maven-repository-aws-s3%22)
[![License](https://travis-ci.org/ehsaniara/maven-repository-aws-s3.svg?branch=master)](https://travis-ci.org/ehsaniara/maven-repository-aws-s3.svg?branch=master)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.ehsaniara/maven-repository-aws-s3/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.ehsaniara/maven-repository-aws-s3)

![AWS S3 and Maven](docs/maven-repository-aws-s3-0.png)

**Introduction**
With the help of this maven-plugin you can create your own private Maven Repository with the essential features. There are many commercial products out there, for example: [Nexus](https://help.sonatype.com/repomanager3/formats/maven-repositories), [JFrog](https://jfrog.com/artifactory/) and ets.., but the drawback is they required more resources (Compute and storage) and some are costly. Where you can simply setup in your AWS cloud with much much less cost.

![High Level Arch.](docs/maven-repository-aws-s3-1.png)

**Start Here**

* [Configure AWS Pre-Req](#Configure-AWS-Pre-Req)
* [Configure By AWS CLI (No ready yet)](#Configure-By-AWS-CLI)
* [Configure By AWS Console](#Configure-By-AWS-Console)
* [Create S3 Bucket](#Create-S3-Bucket)
* [Create Policy](#Create-Policy)
* [Create IAM USER](#Create-IAM-USER)
* [Local PC Setup](#Local-PC-Setup)
* [CI/CD Pipeline Setup](#CI-CD-Pipeline-Setup)
* [Reference](#Reference)

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.ehsaniara/maven-repository-aws-s3/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.ehsaniara/maven-repository-aws-s3)
[![License](https://travis-ci.org/ehsaniara/maven-repository-aws-s3.svg?branch=master)](https://travis-ci.org/ehsaniara/maven-repository-aws-s3.svg?branch=master)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.ehsaniara/maven-repository-aws-s3.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.ehsaniara%22%20AND%20a:%22maven-repository-aws-s3%22)


## Configure AWS Pre-Req
Create IAM User, -Rule and -Policy.

You can use both AWS-CLI or Web Console (browser: https://aws.amazon.com/)

##### NOTE: Java 1.8 and 11 supporteds


## Configure By AWS CLI:

> Note: make sure that you have latest AWS CLI installed in your PC.
> Note: make sure that you are in your project root directory and have permission to create a file.

```shell script
curl -s https://raw.githubusercontent.com/ehsaniara/maven-repository-aws-s3/master/aws-s3-setup.sh | bash /dev/stdin bucket_name username
```
###### Note: Currently AWS CLI script is not completed, Please try AWS Console one


## Configure By AWS Console
(browser: https://aws.amazon.com/)


### Create S3 Bucket

Create a AWS S3 bucket, try to have unique name from you domain, for example: ```my-project-com-maven-repository```
###### Note: Block all public access on the bucket
and also create 2 folder of ```release``` and ```snapshot``` in it.


### Create Policy
Create policy with the following json (select json tab):

##### Note: dont forget to replace ```YOUR_BUCKET_NAME``` by your bucket name, for example: ```my-project-com-maven-repository```
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:CreateBucket",
"s3:ListBucket",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
}
]
}
```
then give name to this policy. something similar to your bucket name, for example: ```my-project-com-maven-repository-policy``` and then create the policy.


### Create IAM USER
on Add user, select a User name and make sure you have select the "Programmatic access"
then select "Attach existing policies directly", and in ```Filter policies``` box search for your the policy name you have just created.
then tag,review and create the user.

> Important: Make sure that you have download the .csv file and store it in the secure place. the credentials in this file is required to user in your ```~/.m2/setting.xml``` file

create a user with (Programmatic access).

* create separate user to access your S3 bucket, for the security reason you should not give admin permission. this user should have enough access to read and write in the bucket and no more than that.
##### Note: you can have as many user (per team member) or single user just for repo access.


## Local PC Setup
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.ehsaniara/maven-repository-aws-s3.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.ehsaniara%22%20AND%20a:%22maven-repository-aws-s3%22)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.ehsaniara/maven-repository-aws-s3/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.ehsaniara/maven-repository-aws-s3)

If you plane to deploy you project jar from your local machine you need to follow the following steps.

* on your local maven setup directory ```.m2``` add the following XML snaps in ```setting.xml```.
you basically gave permission to maven to access the S3 bucket, to be able to push or pull the files. one for **snapshot** and one for **release**.

##### Note: create ```setting.xml``` if it's not exist in ```.m2``` directory
```xml


...
...

YOUR_BUCKET_NAME-snapshot
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY

AWS_REGION
false



YOUR_BUCKET_NAME-release
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY

AWS_REGION
false


....
....

```

* on your project ```pom.xml``` add the following xml to let maven **DOWNLOAD** your project artifactory from the maven-repo
```xml


YOUR_BUCKET_NAME-snapshot
s3://YOUR_BUCKET_NAME/snapshot


YOUR_BUCKET_NAME-release
s3://YOUR_BUCKET_NAME/release

```
##### Note: make sure that```YOUR_BUCKET_NAME-snapshot``` and ```YOUR_BUCKET_NAME-release``` should be identical with your ```.m2/setting.xml``` ids

* The following xml is required if you want ,user be able to upload into maven repo., from its terminal or idea
on your project ```pom.xml``` add the following xml to let maven **UPLOAD** your project artifactory into the maven-repo
```xml


YOUR_BUCKET_NAME-snapshot
s3://YOUR_BUCKET_NAME/snapshot


YOUR_BUCKET_NAME-release
s3://YOUR_BUCKET_NAME/release

```

And the most important one, add the following xml in your project ```pom.xml``` with in the `````` tag

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.ehsaniara/maven-repository-aws-s3/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.ehsaniara/maven-repository-aws-s3)

```xml

...


com.github.ehsaniara
maven-repository-aws-s3
1.2.11


...

```

for Example:

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.ehsaniara/maven-repository-aws-s3/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.ehsaniara/maven-repository-aws-s3)

```xml



org.springframework.boot
spring-boot-maven-plugin



build-info





org.apache.maven.plugins
maven-compiler-plugin
3.8.1

11




com.github.ehsaniara
maven-repository-aws-s3
1.2.11


```

once you have setup your pom.xml file in your project you can run the following line:

```shell script
# to clean your target directory
mvn clean
# deploy your artifactory into you maven-repo (AWS S3 Bucket)
mvn deploy
```


## CI/CD Pipeline Setup
[updating soon..]


## Reference

Apache wagon: http://maven.apache.org/wagon/