Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for YUM and APT package repositories and GCP Blobstore #42

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
cb9b37c
Taking patch from rastaman@github
steven-edgar Feb 1, 2019
8258e66
Adding support for yum repos
steven-edgar Feb 15, 2019
60a2a54
Yum repo support
steven-edgar Feb 15, 2019
28024c8
Attempt at apt proxy create repo
steven-edgar Feb 20, 2019
c80a513
Attempt at apt proxy create repo
steven-edgar Feb 20, 2019
a7ec976
Adding APT support
steven-edgar Feb 20, 2019
5333cd7
debugging
steven-edgar Feb 21, 2019
98c8e27
Adding apt proxy script upload
steven-edgar Feb 21, 2019
5e9467e
Adding apt proxy script upload
steven-edgar Feb 21, 2019
cecb320
Adding apt proxy script upload
steven-edgar Feb 21, 2019
7ae1106
Adding GCP Blobstore support
steven-edgar Feb 22, 2019
49aa7a8
Adding GCP Blobstore support
steven-edgar Feb 22, 2019
6b4be44
Adding GCP Blobstore support
steven-edgar Feb 22, 2019
e631d4f
Adding GCP Blobstore support
steven-edgar Feb 22, 2019
7870b2d
Adding GCP Blobstore support
steven-edgar Feb 22, 2019
e6f1ed3
Adding GCP Blobstore support
steven-edgar Feb 22, 2019
fb786bb
Adding GCP Blobstore support
steven-edgar Feb 22, 2019
d749bc3
Adding GCP Blobstore support
steven-edgar Feb 22, 2019
a0aad65
Adding GCP Blobstore support
steven-edgar Feb 22, 2019
726d671
Adding support for installing plugins via other ansible roles
steven-edgar Feb 25, 2019
775b657
Adding support for installing plugins via other ansible roles
steven-edgar Feb 25, 2019
c917452
Adding support for installing plugins via other ansible roles
steven-edgar Feb 25, 2019
8e63a1e
Adding APT repo and GCP Blobstore plugins to docs
steven-edgar Feb 25, 2019
58bb1ab
Adding APT repo and GCP Blobstore plugins to docs
steven-edgar Feb 25, 2019
161034e
Allowing for nexus db restoration
steven-edgar Apr 4, 2019
52af551
Removing backup restore
steven-edgar Apr 4, 2019
2df5a50
Adding proxy settings to vm options
steven-edgar Jul 11, 2019
32af282
Merge pull request #1 from sky-uk/dto-20297-use-local-services
steven-edgar Jul 12, 2019
50a189b
Remerge from upstream
steven-edgar Jan 8, 2020
966439a
Remerge from upstream
steven-edgar Jan 8, 2020
9397118
Remerge from upstream
steven-edgar Jan 8, 2020
40571d5
Changes for nexus 3.20
steven-edgar Jan 9, 2020
f8d3402
Correcting uri
steven-edgar Jan 9, 2020
0f1eaec
Change admin password if 1st install
steven-edgar Jan 9, 2020
a823893
Password issues
steven-edgar Jan 9, 2020
d0bbc0e
Password issues
steven-edgar Jan 9, 2020
98fb330
Password issues
steven-edgar Jan 9, 2020
3a4a009
Password issues
steven-edgar Jan 9, 2020
0a4e401
Password issues
steven-edgar Jan 9, 2020
2bca62e
Create blobstore groovy script fixes for 3.20
steven-edgar Jan 10, 2020
d3394e8
Password changes
steven-edgar Jan 10, 2020
0c629d6
Password changes
steven-edgar Jan 10, 2020
6483f82
Create blobstore groovy script fixes for 3.20
steven-edgar Jan 10, 2020
cd313db
Create blobstore groovy script fixes for 3.20
steven-edgar Jan 10, 2020
4027f00
Create blobstore groovy script fixes for 3.20
steven-edgar Jan 10, 2020
0183232
Create blobstore groovy script fixes for 3.20
steven-edgar Jan 10, 2020
944f189
Changing DB backup to run every minute
steven-edgar Jan 10, 2020
b177845
Removing backup script
steven-edgar Jan 10, 2020
1986fe5
Removing secret - now invalidated
steven-edgar Jan 17, 2020
52d3c10
Merge pull request #2 from sky-uk/feature/dto-24155-nexus-upgrade
steven-edgar Jan 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ Delete the default blobstore from the nexus install initial default configuratio

[Blobstores](https://books.sonatype.com/nexus-book/3.0/reference/admin.html#admin-repository-blobstores) to create. A blobstore path and a repository blobstore cannot be updated after initial creation (any update here will be ignored on re-provisionning).

nexus_blobstores_gcp: []
# example Google Bucket backed blobstore item:
# - name: "gcp_blobstore"
# bucket: "my-gcp-bucket-name"
# credentials: "/opt/nexus-latest/system/gcloud-nexus-key.json"
Google Cloud Platform storage bucket backed blobstore to create. Note that this requires installation of the GCP Blobstore Nexus plugin before it can be created. If you have an Ansible role to do this you can install it prior to blobstore creation by including the role in the nexus_plugins_installation_roles list.

nexus_scheduled_tasks: []
# example task to compact blobstore :
# - name: compact-blobstore
Expand Down Expand Up @@ -264,7 +271,7 @@ All three repository types are combined with the following default values :
write_policy: allow_once # allow_once or allow
```

Docker, Pypi, Raw, Rubygems, Bower, NPM, and Git-LFS repository types:
Docker, Pypi, Raw, Rubygems, Bower, NPM, Git-LFS, YUM and APT repository types:
see `defaults/main.yml` for these options:

nexus_config_pypi: false
Expand All @@ -274,6 +281,10 @@ see `defaults/main.yml` for these options:
nexus_config_bower: false
nexus_config_npm: false
nexus_config_gitlfs: false
nexus_config_yum: false
nexus_config_apt: false

NOTE: APT repositories require the installation of the APT repository Nexus plugin, see the Plugins section towards the end of this document.

These are all false unless you override them from playbook / group_var / cli, these all utilize the same mechanism as maven.

Expand Down Expand Up @@ -393,6 +404,17 @@ The java and httpd requirements /can/ be fulfilled with the following galaxy rol

```

Plugins
-------
Nexus plugins can be installed as part of the Nexus installation using this role by adding them into the nexus_plugins_installation_roles list. This requires that you have added Ansible roles to do the installation of the plugins. These plugins will be installed after the base Nexus installation, before the creation of blobstores, repositories, etc.
nexus_plugins_installation_roles:
- "nexus-repository-apt"
- "nexus-blobstore-google-cloud"
For the Google Cloud Platform Nexus Blobstore Nexus plugin see
https://github.com/sonatype-nexus-community/nexus-blobstore-google-cloud
For the APT repository plugin see
https://github.com/sonatype-nexus-community/nexus-repository-apt

License
-------

Expand Down
21 changes: 19 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ nexus_config_rubygems: false
nexus_config_bower: false
nexus_config_npm: false
nexus_config_gitlfs: false
nexus_config_yum: false

# also see _nexus_privilege_defaults below
nexus_privileges:
Expand Down Expand Up @@ -138,7 +139,8 @@ nexus_blob_names: # Splited blob name list @ blob_vars.yml
blob: 'default'
gitlfs:
blob: 'default'

yum:
blob: 'default'

nexus_blobstores: []
# example blobstore item :
Expand Down Expand Up @@ -170,9 +172,15 @@ nexus_repos_maven_group:
- central
- jboss

nexus_repos_yum_proxy: []
nexus_repos_yum_hosted: []
nexus_repos_yum_group: []

nexus_repos_apt_proxy: []


nexus_scheduled_tasks:
- name: db-backup # Note: CRON must be aligned to nexus-blob-backup.sh cron schedule. -> Task: "Config nexus-backup shell cron"
- name: db-backup
cron: '0 0 21 * * ?'
typeId: db.backup
taskProperties:
Expand Down Expand Up @@ -341,6 +349,15 @@ nexus_repos_npm_proxy:
blob_store: "{{ nexus_blob_names.npm.blob }}"
remote_url: https://registry.npmjs.org

_nexus_repos_yum_defaults:
blob_store: "{{ nexus_blob_names.npm.blob }}"
strict_content_validation: true
write_policy: allow_once # allow_once or allow

_nexus_repos_apt_defaults:
blob_store: "{{ nexus_blob_names.npm.blob }}"
strict_content_validation: true

# gitlfs support
_nexus_repos_gitlfs_defaults:
blob_store: "{{ nexus_blob_names.gitlfs.blob }}"
Expand Down
24 changes: 24 additions & 0 deletions files/groovy/create_blobstore_gcp.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import groovy.json.JsonSlurper
import org.sonatype.nexus.blobstore.api.BlobStoreManager

parsed_args = new JsonSlurper().parseText(args)

existingBlobStore = blobStore.getBlobStoreManager().get(parsed_args.name)
if (existingBlobStore == null) {

def blobStoreManager = container.lookup(BlobStoreManager.class.name)
def config = blobStoreManager.newConfiguration()
config.name = 'gcp'
config.type = 'Google Cloud Storage'
config.setAttributes(
'google cloud storage': [
bucket: parsed_args.bucket,
credential_file: parsed_args.credentials,
region: parsed_args.region
]
)

blobStoreManager.create(config)

}

63 changes: 63 additions & 0 deletions files/groovy/create_repo_apt_proxy.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import groovy.json.JsonSlurper
import org.sonatype.nexus.repository.config.Configuration

parsed_args = new JsonSlurper().parseText(args)

repositoryManager = repository.repositoryManager

authentication = parsed_args.remote_username == null ? null : [
type: 'username',
username: parsed_args.remote_username,
password: parsed_args.remote_password
]

existingRepository = repositoryManager.get(parsed_args.name)

if (existingRepository != null) {

newConfig = existingRepository.configuration.copy()
// We only update values we are allowed to change (cf. greyed out options in gui)
newConfig.attributes['proxy']['remoteUrl'] = parsed_args.remote_url
newConfig.attributes['httpclient']['authentication'] = authentication
newConfig.attributes['storage']['strictContentTypeValidation'] = Boolean.valueOf(parsed_args.strict_content_validation)

repositoryManager.update(newConfig)

} else {

configuration = new Configuration(
repositoryName: parsed_args.name,
recipeName: 'apt-proxy',
online: true,
attributes: [
apt: [
distribution: parsed_args.distribution,
flat: parsed_args.get('flat', false)
],
proxy : [
remoteUrl: parsed_args.remote_url,
contentMaxAge: parsed_args.get('content_max_age', 1440.0),
metadataMaxAge: parsed_args.get('metadata_max_age', 1440.0)
],
httpclient: [
blocked: false,
autoBlock: true,
authentication: authentication,
connection: [
useTrustStore: false
]
],
storage: [
blobStoreName: parsed_args.blob_store,
strictContentTypeValidation: Boolean.valueOf(parsed_args.strict_content_validation)
],
negativeCache: [
enabled: parsed_args.get("negative_cache_enabled", true),
timeToLive: parsed_args.get("negative_cache_ttl", 1440.0)
]
]
)

repositoryManager.create(configuration)

}
38 changes: 38 additions & 0 deletions files/groovy/create_repo_yum_group.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import groovy.json.JsonSlurper
import org.sonatype.nexus.repository.config.Configuration

parsed_args = new JsonSlurper().parseText(args)

repositoryManager = repository.repositoryManager

existingRepository = repositoryManager.get(parsed_args.name)

if (existingRepository != null) {

newConfig = existingRepository.configuration.copy()
// We only update values we are allowed to change (cf. greyed out options in gui)
newConfig.attributes['group']['memberNames'] = parsed_args.member_repos
newConfig.attributes['storage']['strictContentTypeValidation'] = Boolean.valueOf(parsed_args.strict_content_validation)

repositoryManager.update(newConfig)

} else {

configuration = new Configuration(
repositoryName: parsed_args.name,
recipeName: 'yum-group',
online: true,
attributes: [
group : [
memberNames: parsed_args.member_repos
],
storage: [
blobStoreName: parsed_args.blob_store,
strictContentTypeValidation: Boolean.valueOf(parsed_args.strict_content_validation)
]
]
)

repositoryManager.create(configuration)

}
41 changes: 41 additions & 0 deletions files/groovy/create_repo_yum_hosted.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import groovy.json.JsonSlurper
import org.sonatype.nexus.repository.config.Configuration

parsed_args = new JsonSlurper().parseText(args)

repositoryManager = repository.repositoryManager

existingRepository = repositoryManager.get(parsed_args.name)

if (existingRepository != null) {

newConfig = existingRepository.configuration.copy()
// We only update values we are allowed to change (cf. greyed out options in gui)
newConfig.attributes['yum']['repodataDepth'] = parsed_args.repodata_depth as Integer
newConfig.attributes['yum']['layoutPolicy'] = parsed_args.layout_policy.toUpperCase()
newConfig.attributes['storage']['writePolicy'] = parsed_args.write_policy.toUpperCase()
newConfig.attributes['storage']['strictContentTypeValidation'] = Boolean.valueOf(parsed_args.strict_content_validation)

repositoryManager.update(newConfig)

} else {

configuration = new Configuration(
repositoryName: parsed_args.name,
recipeName: 'yum-hosted',
online: true,
attributes: [
yum : [
repodataDepth : parsed_args.repodata_depth.toInteger(),
layoutPolicy : parsed_args.layout_policy.toUpperCase()
],
storage: [
writePolicy: parsed_args.write_policy.toUpperCase(),
blobStoreName: parsed_args.blob_store,
strictContentTypeValidation: Boolean.valueOf(parsed_args.strict_content_validation)
]
]
)

repositoryManager.create(configuration)
}
59 changes: 59 additions & 0 deletions files/groovy/create_repo_yum_proxy.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import groovy.json.JsonSlurper
import org.sonatype.nexus.repository.config.Configuration

parsed_args = new JsonSlurper().parseText(args)

repositoryManager = repository.repositoryManager

authentication = parsed_args.remote_username == null ? null : [
type: 'username',
username: parsed_args.remote_username,
password: parsed_args.remote_password
]

existingRepository = repositoryManager.get(parsed_args.name)

if (existingRepository != null) {

newConfig = existingRepository.configuration.copy()
// We only update values we are allowed to change (cf. greyed out options in gui)
newConfig.attributes['proxy']['remoteUrl'] = parsed_args.remote_url
newConfig.attributes['httpclient']['authentication'] = authentication
newConfig.attributes['storage']['strictContentTypeValidation'] = Boolean.valueOf(parsed_args.strict_content_validation)

repositoryManager.update(newConfig)

} else {

configuration = new Configuration(
repositoryName: parsed_args.name,
recipeName: 'yum-proxy',
online: true,
attributes: [
proxy : [
remoteUrl: parsed_args.remote_url,
contentMaxAge: parsed_args.get('content_max_age', 1440.0),
metadataMaxAge: parsed_args.get('metadata_max_age', 1440.0)
],
httpclient: [
blocked: false,
autoBlock: true,
authentication: authentication,
connection: [
useTrustStore: false
]
],
storage: [
blobStoreName: parsed_args.blob_store,
strictContentTypeValidation: Boolean.valueOf(parsed_args.strict_content_validation)
],
negativeCache: [
enabled: parsed_args.get("negative_cache_enabled", true),
timeToLive: parsed_args.get("negative_cache_ttl", 1440.0)
]
]
)

repositoryManager.create(configuration)

}
2 changes: 1 addition & 1 deletion tasks/call_script.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Calling Groovy script {{ script_name }}
uri:
url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}service/siesta/rest/v1/script/{{ script_name }}/run"
url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}service/rest/v1/script/{{ script_name }}/run"
user: 'admin'
password: "{{ current_nexus_admin_password }}"
headers:
Expand Down
36 changes: 36 additions & 0 deletions tasks/change_admin_password.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---

- name: Check if admin password written by system
stat:
path: "{{ nexus_data_dir }}/admin.password"
register: password_file

- name: Change the admin user password
uri:
url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}service/rest/beta/security/users/admin/change-password"
user: 'admin'
password: "{{ lookup('file', nexus_data_dir + '/admin.password') }}"
body: "{{ current_nexus_admin_password }}"
method: PUT
force_basic_auth: yes
status_code: 204,404,401
headers:
Content-Type: "text/plain"
when: password_file.stat is defined and password_file.stat.exists

- name: Check the password
uri:
url: "http://localhost:{{ nexus_default_port }}{{ nexus_default_context_path }}service/rest/v1/script"
user: 'admin'
password: "{{ current_nexus_admin_password }}"
method: GET
force_basic_auth: yes
status_code: 200

#If we get this far then password file no longer required, delete it
- name: Delete admin password file
file:
path: "{{ nexus_data_dir }}/admin.password"
state: absent
when: password_file.stat is defined and password_file.stat.exists

6 changes: 6 additions & 0 deletions tasks/create_blobstore_gcp_each.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

- include: call_script.yml
vars:
script_name: create_blobstore_gcp
args: "{{ item }}"
5 changes: 5 additions & 0 deletions tasks/create_repo_apt_proxy_each.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- include: call_script.yml
vars:
script_name: create_repo_apt_proxy
args: "{{ _nexus_repos_apt_defaults|combine(item) }}"
5 changes: 5 additions & 0 deletions tasks/create_repo_yum_group_each.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- include: call_script.yml
vars:
script_name: create_repo_yum_group
args: "{{ _nexus_repos_yum_defaults|combine(item) }}"
Loading