Skip to content

Commit

Permalink
Merge pull request #221 from 030/208-windows-upload
Browse files Browse the repository at this point in the history
[GH-208] Use Packer and Vagrant in order to test N3DR on Windows.
  • Loading branch information
030 authored Oct 11, 2021
2 parents 4d8b317 + 0b0f687 commit c39a0a9
Show file tree
Hide file tree
Showing 12 changed files with 467 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ vendor
.vscode
*.zip
coverage.txt
*.snap.xdelta3
*.snap.xdelta3
.vagrant
virtualbox*
*.exe
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [6.0.13] - 2021-10-11

### Fixed

- Resolve gosec G304, G307, G401 and G501 issues.
- Upload fails from Windows, reported by
[TheMaddinFromTqg](https://github.com/TheMaddinFromTqg).

## [6.0.12] - 2021-10-09

Expand Down Expand Up @@ -548,7 +552,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Download all artifacts from a certain Nexus3 repository.

[Unreleased]: https://github.com/030/n3dr/compare/6.0.12...HEAD
[Unreleased]: https://github.com/030/n3dr/compare/6.0.13...HEAD
[6.0.13]: https://github.com/030/n3dr/compare/6.0.12...6.0.13
[6.0.12]: https://github.com/030/n3dr/compare/6.0.11...6.0.12
[6.0.11]: https://github.com/030/n3dr/compare/6.0.10...6.0.11
[6.0.10]: https://github.com/030/n3dr/compare/6.0.9...6.0.10
Expand Down
42 changes: 39 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ option.
### Build

```bash
docker build -t utrecht/n3dr:6.0.12 .
docker build -t utrecht/n3dr:6.0.13 .
```

[![dockeri.co](https://dockeri.co/image/utrecht/n3dr)](https://hub.docker.com/r/utrecht/n3dr)
Expand All @@ -177,7 +177,7 @@ docker build -t utrecht/n3dr:6.0.12 .
```bash
docker run -it \
-v /home/${USER}/.n3dr:/root/.n3dr \
-v /tmp/n3dr:/tmp/n3dr utrecht/n3dr:6.0.12
-v /tmp/n3dr:/tmp/n3dr utrecht/n3dr:6.0.13
```

### Upload
Expand All @@ -186,7 +186,7 @@ docker run -it \
docker run -it \
--entrypoint=/bin/ash \
-v /home/${USER}/.n3dr:/root/.n3dr \
-v /tmp/n3dr:/tmp/n3dr utrecht/n3dr:6.0.12
-v /tmp/n3dr:/tmp/n3dr utrecht/n3dr:6.0.13
```

navigate to the repository folder, e.g. `/tmp/n3dr/download*/` and upload:
Expand Down Expand Up @@ -396,3 +396,39 @@ a single command.
```bash
go test internal/artifacts/common.go internal/artifacts/common_test.go
```

### Integration testing on Windows

#### Packer

```bash
packer init packer/windows2016.json.pkr.hcl
PACKER_LOG=1 packer build packer/windows2016.json.pkr.hcl
```

#### Vagrant

```bash
vagrant box add virtualbox_windows2016.box --name win2016/n3dr
vagrant box list
vagrant plugin install vagrant-reload vagrant-windows-update
export VAGRANT_N3DR_NETWORK_ADAPTER=$(vboxmanage list bridgedifs |\
grep Name: | head -1 | awk '{ print $2 }')
VAGRANT_NEXUS3_IP=192.168.0.42 VAGRANT_N3DR_IP=192.168.0.43 vagrant up
vagrant provision nexus3
vagrant destroy -f
vagrant ssh nexus3
```

Login as `vagrant` with pass `vagrant` and issue:

```bash
cd C:\vagrant
.\cmd\n3dr\n3dr.exe download -r maven-releases -n http://192.168.0.42:9999 \
-u admin -p some-password
.\cmd\n3dr\n3dr.exe upload -r maven-releases -n http://192.168.0.42:9999 \
-u admin -p some-password
```

To check whether it is possible to upload artifacts to Nexus3 from Windows
using N3DR.
42 changes: 42 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Vagrant.require_version ">= 2.2.18"

Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |v|
v.gui = true
v.customize ['setextradata', :id, 'GUI/ScaleFactor', '2.0']
v.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
v.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
v.customize ["modifyvm", :id, "--memory", "2048"]
v.customize ["modifyvm", :id, "--cpus", "2"]
end

config.vm.define "n3dr" do |n3dr|
n3dr.vm.guest = :windows
n3dr.vm.communicator = "winrm"
n3dr.winrm.username = "vagrant"
n3dr.winrm.password = "vagrant"
n3dr.vm.box = "win2016/n3dr"
n3dr.vm.hostname = "n3dr"
n3dr.vm.network "public_network",
ip: ENV['VAGRANT_N3DR_IP'],
bridge: ENV['VAGRANT_N3DR_NETWORK_ADAPTER']
n3dr.vm.provision "shell",
path: "vagrant/scripts/n3dr.ps1"
n3dr.vm.provision "windows-update", filters: [
"exclude:$_.Title -like '*Preview*'",
"include:$_.Title -like '*Cumulative Update for *'",
"include:$_.AutoSelectOnWebSites"]
end

config.vm.define "nexus3" do |nexus3|
nexus3.vm.box = "ubuntu/focal64"
nexus3.vm.hostname = "nexus3"
nexus3.vm.network "public_network",
ip: ENV['VAGRANT_NEXUS3_IP'],
bridge: ENV['VAGRANT_N3DR_NETWORK_ADAPTER']
nexus3.vm.provision "shell" do |s|
s.path = "vagrant/scripts/nexus3.sh"
s.env = { "N3DR_APT_GPG_SECRET" => ENV['N3DR_APT_GPG_SECRET'] }
end
end
end
2 changes: 1 addition & 1 deletion build/package/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: n3dr
base: core20
version: 6.0.12
version: 6.0.13
summary: Nexus3 Disaster Recovery
description: |
Download all artifacts at once or migrate automatically from Nexus to Nexus.
Expand Down
12 changes: 9 additions & 3 deletions internal/artifacts/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"

Expand Down Expand Up @@ -68,8 +69,13 @@ func sbArtifact(sb *strings.Builder, path, ext, classifier string) error {
return nil
}

func artifactTypeDetector(sb *strings.Builder, path string, skipErrors bool) error {
var err error
func artifactTypeDetector(sb *strings.Builder, path string, skipErrors bool) (err error) {
regexBase := `^.*\/([\w\-\.]+)\/`

if runtime.GOOS == "windows" {
log.Info("N3DR is running on Windows. Correcting the regexBase...")
regexBase = `^.*\\([\w\-\.]+)\\`
}

regexVersion := `(([a-z\d\-]+)|(([a-z\d\.]+)))`
if rv := os.Getenv("N3DR_MAVEN_UPLOAD_REGEX_VERSION"); rv != "" {
Expand All @@ -81,7 +87,7 @@ func artifactTypeDetector(sb *strings.Builder, path string, skipErrors bool) err
regexClassifier = rc
}

re := regexp.MustCompile(`^.*\/([\w\-\.]+)\/` + regexVersion + regexClassifier + `\.([a-z]+)$`)
re := regexp.MustCompile(regexBase + regexVersion + regexClassifier + `\.([a-z]+)$`)

classifier := ""
if re.Match([]byte(path)) {
Expand Down
163 changes: 163 additions & 0 deletions packer/Autounattend.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="specialize">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ComputerName>vagrant-win2016</ComputerName>
<RegisteredOrganization>Microsoft</RegisteredOrganization>
<!-- https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-time-zones -->
<TimeZone>W. Europe Standard Time</TimeZone>
</component>
<component name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SkipAutoActivation>true</SkipAutoActivation>
</component>
<component name="Microsoft-Windows-ServerManager-SvrMgrNc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DoNotOpenServerManagerAtLogon>true</DoNotOpenServerManagerAtLogon>
</component>
<component name="Microsoft-Windows-IE-ESC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<IEHardenAdmin>false</IEHardenAdmin>
<IEHardenUser>false</IEHardenUser>
</component>
<component name="Microsoft-Windows-IE-InternetExplorer" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SearchScopes>
<Scope wcm:action="add">
<ScopeDefault>true</ScopeDefault>
<ScopeDisplayName>Google</ScopeDisplayName>
<ScopeKey>Google</ScopeKey>
<ScopeUrl>http://www.google.com/search?q={searchTerms}</ScopeUrl>
</Scope>
</SearchScopes>
<DisableAccelerators>true</DisableAccelerators>
<DisableFirstRunWizard>true</DisableFirstRunWizard>
<Home_Page>about:blank</Home_Page>
</component>
<component name="Microsoft-Windows-TerminalServices-LocalSessionManager" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fDenyTSConnections>false</fDenyTSConnections>
</component>
<component name="Microsoft-Windows-TerminalServices-RDP-WinStationExtensions" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserAuthentication>0</UserAuthentication>
</component>
<component name="Networking-MPSSVC-Svc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FirewallGroups>
<FirewallGroup wcm:action="add" wcm:keyValue="RemoteDesktop">
<Active>true</Active>
<Group>Remote Desktop</Group>
<Profile>all</Profile>
</FirewallGroup>
</FirewallGroups>
</component>
<component name="Microsoft-Windows-OutOfBoxExperience" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DoNotOpenInitialConfigurationTasksAtLogon>true</DoNotOpenInitialConfigurationTasksAtLogon>
</component>
</settings>
<settings pass="windowsPE">
<component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ImageInstall>
<OSImage>
<InstallTo>
<DiskID>0</DiskID>
<PartitionID>1</PartitionID>
</InstallTo>
<InstallFrom>
<MetaData wcm:action="add">
<Key>/IMAGE/NAME</Key>
<Value>Windows Server 2016 SERVERSTANDARD</Value>
</MetaData>
</InstallFrom>
<WillShowUI>OnError</WillShowUI>
<InstallToAvailablePartition>false</InstallToAvailablePartition>
</OSImage>
</ImageInstall>
<UserData>
<AcceptEula>true</AcceptEula>
<FullName>Vagrant Administrator</FullName>
<Organization>Vagrant Inc.</Organization>
</UserData>
<DiskConfiguration>
<Disk wcm:action="add">
<CreatePartitions>
<CreatePartition wcm:action="add">
<Order>1</Order>
<Type>Primary</Type>
<Extend>true</Extend>
</CreatePartition>
</CreatePartitions>
<ModifyPartitions>
<ModifyPartition wcm:action="add">
<Active>true</Active>
<Extend>false</Extend>
<Format>NTFS</Format>
<Label></Label>
<Letter>C</Letter>
<Order>1</Order>
<PartitionID>1</PartitionID>
</ModifyPartition>
</ModifyPartitions>
<DiskID>0</DiskID>
<WillWipeDisk>true</WillWipeDisk>
</Disk>
<WillShowUI>OnError</WillShowUI>
</DiskConfiguration>
</component>
<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<InputLocale>en-US</InputLocale>
<SystemLocale>en-US</SystemLocale>
<UILanguage>en-US</UILanguage>
<UserLocale>en-US</UserLocale>
</component>
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UserAccounts>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>
<Value>dgBhAGcAcgBhAG4AdABQAGEAcwBzAHcAbwByAGQA</Value>
<PlainText>false</PlainText>
</Password>
<Description>Vagrant User</Description>
<DisplayName>vagrant</DisplayName>
<Group>Administrators</Group>
<Name>vagrant</Name>
</LocalAccount>
</LocalAccounts>
</UserAccounts>
<AutoLogon>
<Password>
<Value>dgBhAGcAcgBhAG4AdABQAGEAcwBzAHcAbwByAGQA</Value>
<PlainText>false</PlainText>
</Password>
<Enabled>true</Enabled>
<Username>vagrant</Username>
</AutoLogon>
<OOBE>
<HideEULAPage>true</HideEULAPage>
<HideLocalAccountScreen>true</HideLocalAccountScreen>
<HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
<HideOnlineAccountScreens>true</HideOnlineAccountScreens>
<HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
<NetworkLocation>Home</NetworkLocation>
<!--
ProtectYourPC:
1 Specifies the recommended level of protection for your computer.
2 Specifies that only updates are installed.
3 Specifies that automatic protection is disabled.
-->
<ProtectYourPC>3</ProtectYourPC>
</OOBE>
<FirstLogonCommands>
<SynchronousCommand wcm:action="add">
<CommandLine>cmd.exe /c a:\winrmConfig.bat</CommandLine>
<Description>Configure WinRM</Description>
<Order>3</Order>
<RequiresUserInput>true</RequiresUserInput>
</SynchronousCommand>
</FirstLogonCommands>
</component>
</settings>
<settings pass="offlineServicing">
<component name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<EnableLUA>false</EnableLUA>
</component>
</settings>
<cpi:offlineImage cpi:source="wim:d:/sources/install.wim#Windows Server 2016 SERVERSTANDARD" xmlns:cpi="urn:schemas-microsoft-com:cpi"/>
</unattend>
Loading

0 comments on commit c39a0a9

Please sign in to comment.