Skip to content

Commit

Permalink
Merge pull request #340 from 030/99-297-csv-count-artifacts
Browse files Browse the repository at this point in the history
feat: [#99][#297] Count number of artifacts and save info to a CSV file.
  • Loading branch information
030 authored Jan 15, 2023
2 parents 1e4dfc8 + 8aef89a commit 9f31e5a
Show file tree
Hide file tree
Showing 19 changed files with 394 additions and 88 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@ name: Integration
'on': push
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
nexus-version: 3.44.0
nexus-api-version: v1
shasum: sha512sum
- os: ubuntu-latest
nexus-version: 3.9.0
nexus-api-version: beta
shasum: sha512sum
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
Expand All @@ -32,5 +21,4 @@ jobs:
env:
N3DR_DELIVERABLE: ${{ env.n3dr-deliverable }}
NEXUS_VERSION: ${{ matrix.nexus-version }}
NEXUS_API_VERSION: ${{ matrix.nexus-api-version }}
N3DR_APT_GPG_SECRET: ${{ secrets.N3DR_APT_GPG_SECRET }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

cmd/n3dr/n3dr
cmd/n3dr/n3dr.sha512.txt
cmd/n3dr/start.sh

dip
dip

test/gpg/my_rsa_key
test/rproxy-nginx-nexus3.conf.tmp
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ ENV USERNAME n3dr
RUN adduser -D -g '' $USERNAME
COPY . /go/${USERNAME}/
WORKDIR /go/${USERNAME}/cmd/${USERNAME}
RUN apk add --no-cache git=~2 && \
RUN apk add --no-cache \
git=~2 && \
CGO_ENABLED=0 go build -ldflags "-X main.Version=${VERSION}" -buildvcs=false && \
cp n3dr /n3dr

FROM alpine:3.17.0
FROM alpine:3.17.1
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /n3dr /usr/local/bin/n3dr
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ The aims of the n3dr tool are:

## Quickstart

Download the [latest N3DR binary](https://github.com/030/n3dr/releases/tag/7.0.3):
Download the [latest N3DR binary](https://github.com/030/n3dr/releases/tag/7.1.0):

```bash
cd /tmp && \
curl -L https://github.com/030/n3dr/releases/download/7.0.3/n3dr-ubuntu-latest \
curl -L https://github.com/030/n3dr/releases/download/7.1.0/n3dr-ubuntu-latest \
-o n3dr-ubuntu-latest && \
curl -L https://github.com/030/n3dr/releases/download/7.0.3/\
curl -L https://github.com/030/n3dr/releases/download/7.1.0/\
n3dr-ubuntu-latest.sha512.txt \
-o n3dr-ubuntu-latest.sha512.txt && \
sha512sum -c n3dr-ubuntu-latest.sha512.txt && \
Expand Down
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: 7.0.3
version: 7.1.0
summary: Nexus3 Disaster Recovery
description: |
Download all artifacts at once or migrate automatically from Nexus to Nexus.
Expand Down
40 changes: 40 additions & 0 deletions cmd/n3dr/count.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"github.com/030/n3dr/internal/app/n3dr/artifactsv2/count"
"github.com/030/n3dr/internal/app/n3dr/connection"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var csv string

// repositoriesCmd represents the repositories command
var countCmd = &cobra.Command{
Use: "count",
Short: "Count the number of artifacts.",
Long: `Count the number of artifacts and write them to a CSV if required.
Examples:
# Return the number of artifacts without logging:
n3dr count --logLevel=none
# Return the number of artifacts and write them to a /tmp/helloworld.csv:
n3dr count --csv /tmp/helloworld
`,
Run: func(cmd *cobra.Command, args []string) {
n := connection.Nexus3{AwsBucket: awsBucket, AwsId: awsId, AwsRegion: awsRegion, AwsSecret: awsSecret, BasePathPrefix: basePathPrefix, FQDN: n3drURL, Pass: n3drPass, User: n3drUser, DownloadDirName: downloadDirName, DownloadDirNameZip: downloadDirNameZip, HTTPS: https, DockerHost: dockerHost, DockerPort: dockerPort, DockerPortSecure: dockerPortSecure, ZIP: zip, RepoName: n3drRepo, SkipErrors: skipErrors, WithoutWaitGroups: withoutWaitGroups, WithoutWaitGroupArtifacts: withoutWaitGroupArtifacts, WithoutWaitGroupRepositories: withoutWaitGroupRepositories}
c := count.Nexus3{Nexus3: &n, CsvFile: csv}

if err := c.Artifacts(); err != nil {
log.Fatal(err)
}
},
Version: rootCmd.Version,
}

func init() {
countCmd.Flags().StringVar(&csv, "csv", "", "write to a csvFile")

rootCmd.AddCommand(countCmd)
}
12 changes: 10 additions & 2 deletions cmd/n3dr/repositoriesV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"github.com/030/n3dr/internal/app/n3dr/artifactsv2"
"github.com/030/n3dr/internal/app/n3dr/artifactsv2/count"
"github.com/030/n3dr/internal/app/n3dr/artifactsv2/name"
"github.com/030/n3dr/internal/app/n3dr/artifactsv2/upload"
"github.com/030/n3dr/internal/app/n3dr/connection"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -69,16 +71,21 @@ Examples:
}
n := connection.Nexus3{AwsBucket: awsBucket, AwsId: awsId, AwsRegion: awsRegion, AwsSecret: awsSecret, BasePathPrefix: basePathPrefix, FQDN: n3drURL, Pass: n3drPass, User: n3drUser, DownloadDirName: downloadDirName, DownloadDirNameZip: downloadDirNameZip, HTTPS: https, DockerHost: dockerHost, DockerPort: dockerPort, DockerPortSecure: dockerPortSecure, ZIP: zip, RepoName: n3drRepo, SkipErrors: skipErrors, WithoutWaitGroups: withoutWaitGroups, WithoutWaitGroupArtifacts: withoutWaitGroupArtifacts, WithoutWaitGroupRepositories: withoutWaitGroupRepositories}
a := artifactsv2.Nexus3{Nexus3: &n}
c := count.Nexus3{Nexus3: &n, CsvFile: csv}
nn := name.Nexus3{Nexus3: &n}

if namesV2 {
if err := a.RepositoryNamesV2(); err != nil {
if err := nn.Repositories(); err != nil {
log.Fatal(err)
}
}

if countV2 {
if err := a.CountRepositoriesV2(); err != nil {
if err := c.Repositories(); err != nil {
log.Fatal(err)
}
}

if backupV2 {
if n.RepoName != "" {
if err := a.SingleRepoBackup(); err != nil {
Expand All @@ -90,6 +97,7 @@ Examples:
}
}
}

if uploadV2 {
u := upload.Nexus3{Nexus3: &n}
if err := u.Upload(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/n3dr/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func n3drHiddenHome() (string, error) {
return "", err
}
n3drHomeDir := filepath.Join(home, cli.HiddenN3DR)
log.Infof("n3drHomeDir: '%v'", n3drHomeDir)
log.Debugf("n3drHomeDir: '%v'", n3drHomeDir)
return n3drHomeDir, nil
}

Expand Down Expand Up @@ -214,7 +214,7 @@ func parseVarsFromConfig() error {

func parseConfig(cfgFile string) error {
if err := viper.ReadInConfig(); err == nil {
log.Infof("Using config file: '%v'", viper.ConfigFileUsed())
log.Debugf("Using config file: '%v'", viper.ConfigFileUsed())
if err := parseVarsFromConfig(); err != nil {
return err
}
Expand Down
22 changes: 1 addition & 21 deletions configs/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
---
issues:
exclude-rules:
- linters:
- gochecknoinits
path: cmd/n3dr/backup.go
text: "don't use `init` function"
- linters:
- gochecknoinits
path: cmd/n3dr/config.go
Expand All @@ -23,7 +19,7 @@ issues:
text: "don't use `init` function"
- linters:
- gochecknoinits
path: cmd/n3dr/repositories.go
path: cmd/n3dr/count.go
text: "don't use `init` function"
- linters:
- gochecknoinits
Expand All @@ -37,22 +33,6 @@ issues:
- gochecknoinits
path: cmd/n3dr/sync.go
text: "don't use `init` function"
- linters:
- gochecknoinits
path: cmd/n3dr/upload.go
text: "don't use `init` function"
- linters:
- unparam
path: internal/app/n3dr/artifacts/npm.go
text: '`body` is unused'
- linters:
- containedctx
path: internal/app/n3dr/artifacts/oci.go
text: found a struct that contains a context.Context field
- linters:
- funlen
path: internal/app/n3dr/artifacts/backup.go
text: Function 'createArtifact' is too long
- linters:
- funlen
path: internal/app/n3dr/artifactsv2/upload/upload.go
Expand Down
9 changes: 8 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
## [Unreleased]


<a name="7.1.0"></a>
## [7.1.0] - 2022-12-31
### Feat
- [[#99](https://github.com/030/n3dr/issues/99)][[#297](https://github.com/030/n3dr/issues/297)] Count number of artifacts and save info to a CSV file.


<a name="7.0.3"></a>
## [7.0.3] - 2023-01-03
### Build
Expand Down Expand Up @@ -322,7 +328,8 @@ The `backup`, `upload` and `repositories` commands have been removed.
<a name="1.0.0"></a>
## 1.0.0 - 2019-05-12

[Unreleased]: https://github.com/030/n3dr/compare/7.0.3...HEAD
[Unreleased]: https://github.com/030/n3dr/compare/7.1.0...HEAD
[7.1.0]: https://github.com/030/n3dr/compare/7.0.3...7.1.0
[7.0.3]: https://github.com/030/n3dr/compare/7.0.2...7.0.3
[7.0.2]: https://github.com/030/n3dr/compare/7.0.1...7.0.2
[7.0.1]: https://github.com/030/n3dr/compare/7.0.0...7.0.1
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ n3dr config \
### Build

```bash
docker build -t utrecht/n3dr:7.0.3 .
docker build -t utrecht/n3dr:7.1.0 .
```

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

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

navigate to the repository folder, e.g. `/tmp/n3dr/download*/` and upload:
Expand Down
Loading

0 comments on commit 9f31e5a

Please sign in to comment.