Skip to content

Commit

Permalink
feat: [#358] Maven2 quickstart.
Browse files Browse the repository at this point in the history
  • Loading branch information
030 committed Mar 19, 2023
1 parent 45ea3ab commit 8e1265c
Show file tree
Hide file tree
Showing 522 changed files with 24,898 additions and 1,644 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ configured by N3DR.
## Quickstarts

- [docker](./docs/quickstarts/DOCKER.md)
- [maven2](./docs/quickstarts/MAVEN2.md)
- [rubygems](./docs/quickstarts/RUBYGEMS.md)

## Instructions
Expand Down
14 changes: 9 additions & 5 deletions cmd/n3dr/configRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

var (
configRepoDockerPortSecure, configRepoDelete, snapshot bool
configRepoDockerPort int32
configRepoName, configRepoRecipe, configRepoType, configRepoProxyURL string
configRepoDockerPortSecure, configRepoDelete, snapshot, strictContentTypeValidation bool
configRepoDockerPort int32
configRepoName, configRepoRecipe, configRepoType, configRepoProxyURL string
)

// configRepositoryCmd represents the configRepository command.
Expand All @@ -29,6 +29,9 @@ Examples:
# Create a Maven2 repository:
n3dr configRepository -u some-user -p some-pass -n localhost:9000 --https=false --configRepoName some-name --configRepoType maven2
# Create a Maven2 repository without strictContentTypeValidation:
n3dr configRepository -u some-user -p some-pass -n localhost:9000 --https=false --configRepoName some-name --configRepoType maven2 --strictContentTypeValidation=false
# Create a Maven2 snapshot repository:
n3dr configRepository -u some-user -p some-pass -n localhost:9000 --https=false --configRepoName some-name --configRepoType maven2 --snapshot
Expand All @@ -39,7 +42,7 @@ Examples:
n3dr configRepository -u admin -p some-pass -n localhost:9000 --https=false --configRepoName 3rdparty-rubygems --configRepoType gem
`,
Run: func(cmd *cobra.Command, args []string) {
n := connection.Nexus3{FQDN: n3drURL, Pass: n3drPass, User: n3drUser}
n := connection.Nexus3{FQDN: n3drURL, Pass: n3drPass, StrictContentTypeValidation: strictContentTypeValidation, User: n3drUser}
r := repository.Repository{Nexus3: n}

if configRepoDelete {
Expand Down Expand Up @@ -110,7 +113,7 @@ Examples:
log.Fatalf("configRepoRecipe: '%s' not supported in conjunction with configRepoType: '%s'", configRepoRecipe, configRepoType)
}
default:
log.Fatalf("configRepoType should not be empty, but: 'apt', 'docker', 'maven', 'raw' or 'yum' and not: '%s'. Did you populate the --configRepoType parameter?", configRepoType)
log.Fatalf("configRepoType should not be empty, but: 'apt', 'docker', 'maven2', 'raw' or 'yum' and not: '%s'. Did you populate the --configRepoType parameter?", configRepoType)
}
},
}
Expand All @@ -130,4 +133,5 @@ func init() {
configRepositoryCmd.Flags().StringVar(&configRepoProxyURL, "configRepoProxyURL", "", "The proxy repository URL, e.g.: 'http://nl.archive.ubuntu.com/ubuntu/'")
configRepositoryCmd.Flags().Int32Var(&configRepoDockerPort, "configRepoDockerPort", 8082, "The docker connector port, e.g. 8082")
configRepositoryCmd.Flags().BoolVar(&configRepoDockerPortSecure, "configRepoDockerPortSecure", false, "Whether the docker connector port should be secure")
configRepositoryCmd.Flags().BoolVar(&strictContentTypeValidation, "strictContentTypeValidation", true, "whether strictContentTypeValidation should be enabled")
}
24 changes: 16 additions & 8 deletions docs/development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,34 @@ Run:
N3DR_CLEAN_IN_CASE_OF_SUCCESS_OR_FAILURE=false ./test/integration-tests.sh
```

Once Nexus had been started, download the go-swagger, swagger.json and
generate internal go-swagger code:
Once Nexus had been started, download the swagger.json:

```bash
curl http://localhost:8081/service/rest/swagger.json -o swagger.json
```

Lookup the `maven2.asset3` json snippet, triplicate it and change it to:
`maven2.asset4` and `maven2.asset5` respectively. After adding the two snippets
and renaming them, download go-swagger and generate internal go-swagger code:

```bash
export GITHUB_URL=https://github.com
export GS_URI=go-swagger/go-swagger/releases/download
export GS_VERSION=v0.29.0
export GS_VERSION=v0.30.4
export GS_URL=${GITHUB_URL}/${GS_URI}/${GS_VERSION}/swagger_linux_amd64
export GS_DIR=internal/app/n3dr/goswagger
curl -L \
${GS_URL} \
-o swagger
chmod +x swagger
mkdir -p internal/goswagger
curl http://localhost:9999/service/rest/swagger.json -o swagger.json
mkdir -p "${GS_DIR}"
./swagger generate client \
--name=nexus3 \
--spec swagger.json \
--target=internal/app/n3dr/goswagger \
--skip-validation
go mod tidy
--target="${GS_DIR}" \
--skip-validation && \
go mod tidy && \
rm swagger*
```

## Unit Tests
Expand Down
81 changes: 81 additions & 0 deletions docs/quickstarts/MAVEN2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Maven2

- [Download N3DR](./snippets/n3dr/DOWNLOAD.md).
- [Start a Nexus3 server](./snippets/nexus3/SERVER.md).
- Create a `some-maven2` repository:

```bash
./n3dr configRepository \
-u admin \
-p $(docker exec -it nexus3-n3dr-src cat /nexus-data/admin.password) \
-n localhost:8081 \
--https=false \
--configRepoName some-maven2 \
--configRepoType maven2
```

- Populate it with artifacts:

```bash
downloadDir=/tmp/some-dir/some-maven2 && \
mkdir -p ${downloadDir} && \
for i in $(seq 20); do
path=${downloadDir}/some/group/1.0.0/1.0.0-${i}
file="Some_Package-1.0.0-${i}"
filePath="${path}/${file}"
mkdir -p ${path}
echo -e "<project>\n<modelVersion>4.0.0</modelVersion>\n<groupId>some.group</groupId>\n<artifactId>Some_Package</artifactId>\n<version>1.0.0-${i}</version>\n</project>" > ${filePath}.pom
dd if=/dev/urandom of=${filePath} bs=1M count=${i}

zip ${filePath}.zip ${filePath}
# jar cvf ${filePath}.jar ${filePath}
cp ${filePath} ${filePath}.jar
cp ${filePath} ${filePath}-javadoc.jar
cp ${filePath} ${filePath}-sources.jar
cp ${filePath} ${filePath}.war
echo hello > ${filePath}.module
ls ${filePath}*

curl -X 'POST' \
localhost:8081/service/rest/v1/components?repository=some-maven2 \
-v \
-f \
-u "admin:$(docker exec -it nexus3-n3dr-src cat /nexus-data/admin.password)" \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F "maven2.asset1=@${filePath}.pom" \
-F "maven2.asset1.extension=pom" \
-F "maven2.asset2=@${filePath}.jar;type=application/x-java-archive" \
-F "maven2.asset2.extension=jar" \
-F "maven2.asset3=@${filePath}.war;type=application/x-java-archive" \
-F "maven2.asset3.extension=war" \
-F "maven2.asset4=@${filePath}.zip" \
-F "maven2.asset4.extension=zip" \
-F "maven2.asset5=@${filePath}.module" \
-F "maven2.asset5.extension=module" \
-F "maven2.asset6=@${filePath}-javadoc.jar;type=application/x-java-archive" \
-F "maven2.asset6.classifier=javadoc" \
-F "maven2.asset6.extension=jar" \
-F "maven2.asset7=@${filePath}-sources.jar;type=application/x-java-archive" \
-F "maven2.asset7.classifier=sources" \
-F "maven2.asset7.extension=jar"
done
```

- [Backup all artifacts](./snippets/n3dr/BACKUP.md).
- [Start another Nexus3 server](./snippets/nexus3/ANOTHERSERVER.md).
- Create a repository in the other Nexus3 server:

```bash
./n3dr configRepository \
-u admin \
-p $(docker exec -it nexus3-n3dr-dest cat /nexus-data/admin.password) \
-n localhost:9000 \
--https=false \
--configRepoName some-maven2 \
--configRepoType maven2
```

- [Upload the artifacts to the other Nexus3 server](./snippets/n3dr/UPLOAD.md).
- [Validate](./snippets/n3dr/VALIDATE.md).
- [Cleanup](./snippets/nexus3/CLEANUP.md).
14 changes: 7 additions & 7 deletions docs/quickstarts/RUBYGEMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ mkdir -p ${downloadDir} && \
for f in chef-17.4.25 chef-18.1.0 puppet-7.23.0 rack-3.0.4.1; do
curl -L https://rubygems.org/downloads/${f}.gem > ${downloadDir}/${f}.gem
curl -X 'POST' \
localhost:8081/service/rest/v1/components?repository=some-rubygems \
-s \
-f \
-u "admin:$(docker exec -it nexus3-n3dr-src cat /nexus-data/admin.password)" \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F "rubygems.asset=@${downloadDir}/${f}.gem;type=application/x-tar"
localhost:8081/service/rest/v1/components?repository=some-rubygems \
-s \
-f \
-u "admin:$(docker exec -it nexus3-n3dr-src cat /nexus-data/admin.password)" \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F "rubygems.asset=@${downloadDir}/${f}.gem;type=application/x-tar"
done
```

Expand Down
2 changes: 1 addition & 1 deletion docs/quickstarts/snippets/n3dr/BACKUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```bash
./n3dr repositoriesV2 \
--backup \
--directory-prefix /tmp/some-dir \
--directory-prefix /tmp/some-dir-backup \
-u admin \
-p $(docker exec -it nexus3-n3dr-src cat /nexus-data/admin.password) \
--dockerPort 8082 \
Expand Down
10 changes: 6 additions & 4 deletions docs/quickstarts/snippets/n3dr/VALIDATE.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# Validate

```bash
dir=/tmp/some-dir-validate
mkdir -p "${dir}"
./n3dr count \
-u admin \
-p $(docker exec -it nexus3-n3dr-src cat /nexus-data/admin.password) \
-n localhost:8081 \
--https=false \
--csv /tmp/some-dir/nexus3-n3dr-src && \
--csv ${dir}/nexus3-n3dr-src && \
./n3dr count \
-u admin \
-p $(docker exec -it nexus3-n3dr-dest cat /nexus-data/admin.password) \
-n localhost:9000 \
--https=false \
--csv /tmp/some-dir/nexus3-n3dr-dest && \
--csv ${dir}/nexus3-n3dr-dest && \
echo "Comparing Nexus3 src content:"
cat /tmp/some-dir/nexus3-n3dr-src.csv | sed -e 1d | cut -d "," -f9- | sha256sum && \
cat ${dir}/nexus3-n3dr-src.csv | sed -e 1d | cut -d "," -f9- | sha256sum && \
echo "with Nexus3 dest:"
cat /tmp/some-dir/nexus3-n3dr-dest.csv | sed -e 1d | cut -d "," -f9- | sha256sum && \
cat ${dir}/nexus3-n3dr-dest.csv | sed -e 1d | cut -d "," -f9- | sha256sum && \
echo "Check whether the sha256sums are identical."
```

0 comments on commit 8e1265c

Please sign in to comment.