Coder Social home page Coder Social logo

miclip / nuget-resource Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 3.0 103.69 MB

Concourse resource that pushes, downloads, extracts dotnet core libraries and applications to and from a nuget feed.

License: MIT License

Dockerfile 2.59% Shell 0.68% Go 96.73%
concourse-resource nuget nuget-packages dotnet

nuget-resource's Introduction

Build Status

Nuget Resource

Pushes, downloads, extracts dotnet core libraries and applications to and from a nuget feed.

Source Configuration

  • nuget_source: Required. URL for nuget feed, only v3 API's are currently supported.

  • nuget_apikey: Required. Nuget server API Key.

  • nuget_timeout: Optional. The timeout for pushing packages to nuget, defaults to 300 seconds.

  • package_Id: Required for Check. Package Name or PackageID as defined in the nuspec or csproj.

  • prerelease: Optional. Whether the package is prerelease or not

Behavior

check: Detect a new version of a package

Requires the package_id and prerelease and nuget details in the source.

Resource:

resource_types:
  - name: nuget
    type: docker-image
    source:
      repository: miclip/nuget-resource
      tag: "latest"

resources:
  - name: nuget-get
    type: nuget 
    source:
      nuget_source: https://www.nuget.org/F/myfeed/api/v3/index.json
      nuget_apikey: {{nuget_apikey}}
      package_id: NugetResource.TestApplication
      prerelease: true

Job:

  name: deploy-service
  public: true
  serial: true
  plan:
  - get: nuget-get
    trigger: true
  - put: cf-resource
    params:
      manifest: nuget-get/manifest.yml
      path: nuget-get/

in: Fetch a package from nuget.

Downloads and unpacks the package into the output of the resource.

out: Push a package.

Given a package the resource will push it to the nuget feed.

Parameters

  • package_path: Required. Path to package file (nupkg)

  • nuget_cache_delay: Optional. Delay to wait between pushing the package and checking latest version. Some feeds like myget.com are cached.

Example Configuration

Resource Type

- name: nuget
  type: docker-image
  source:
    repository: miclip/nuget-resource
    tag: "latest"

Resource

- name: nuget-out
  type: nuget 
  source:
    nuget_source: https://www.nuget.org/F/myfeed/api/v3/index.json
    nuget_apikey: {{nuget_apikey}}
    package_id: NugetResource.TestApplication
    prerelease: true

Job

- name: build-service
  public: true
  serial: true
  plan:
  - get: app-repo
    trigger: true
  - task: build-and-pkg
    file: app-repo/ci/tasks/build.yml
  - put: nuget-out
    params: 
      package_path: build-output/*.nupkg

Development

Prerequisites

  • golang is required - version 1.11.x is tested; earlier versions may also work.
  • docker is required - version 18.06.x is tested; earlier versions may also work.
  • dep is used for dependency management of the golang packages.

Running the tests

The tests have been embedded with the Dockerfile; ensuring that the testing environment is consistent across any docker enabled platform. When the docker image builds, the test are run inside the docker container, on failure they will stop the build.

Run the tests with the following command:

docker build -t nuget-resource .

Examples

Dotnet core MVC Application with tests:

https://github.com/miclip/nuget-resource-test-application

nuget-resource's People

Contributors

miclip avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

nuget-resource's Issues

DownloadPackage fails if 'PackageBaseAddress/3.0.0' API endpoint does not have a trailing slash

The issue appears to be that the string concatenation in the line below assumes that downloadUrl will always have a trailing slash:

req, err := http.NewRequest(http.MethodGet, downloadURL+queryParams, nil)

This is true for https://api.nuget.org/v3/index.json, but from what I can tell, a trailing slash isn't required in the service index documentation --even though one is included in their sample.

In particular, BaGet does not include a trailing slash in the service index it creates, and nuget-resource fails to unarchive a package after generating a download request similar to the one below for a package with ID "MyPackageName" and version 0.1.0:

GET /v3/packageMyPackageName/0.1.0/MyPackageName.0.1.0.nupkg

Where are the configuration files?

The readme show what appears to be part of a yaml sample configuration but provides no explanation as to where this code goes. Is this one or many configuration files? Which directory are they copied to in the container? Did I overlook a file in this repository that provides the configuration file?

Issue Could not find PackageBaseAddress/3.0.0 Endpoint after successful publish

Hello, when I try to push out the package it successfully uploads it to our nuget repo and then it fails on a second step.

The code:

  - name: nuget-out
    type: nuget 
    source:
      nuget_source: {{nuget-source}}
      nuget_apikey: {{nuget-api-key}}
      package_id: {{package-id}}
      prerelease: true
    - put: nuget-out
      params: 
        package_path: build-output/*.nupkg

Error:

failed to get download url from api
Could not find PackageBaseAddress/3.0.0 Endpoint

It seems that our nuget repo does not have the PackageBaseAddress Endpoint.
Is there any way to skip this download?

NuGet publish fails on Nexus host because code does not use HTTPS

Using your resource fails for me because of the following error:

packagepath: /tmp/build/put/rf-exceptions/bin/Release2022/12/21 10:44:14 error getting publish url from apierror getting Service Index 401
Please note: There's also an error in the string output concatenation.

This is because the custom host that I'm trying to publish to is a Nexus repository, which declines HTTP methods and requires HTTPS instead.

I believe this is due to your code:

func (client *nugetclientv3) GetServiceIndex(ctx context.Context) (*ServiceIndex, error) {

	req, err := http.NewRequest(http.MethodGet, client.FeedURL, nil)
	if err != nil {
		return nil, err
	}
	req = req.WithContext(ctx)
	req.Header.Add("accept", "application/json")
	var netClient = &http.Client{
		Timeout: 10 * time.Second,
	}
	res, err := netClient.Do(req)
	if err != nil {
		return nil, err
	}
	if res.StatusCode != 200 {
		return nil, fmt.Errorf("error getting Service Index %d", res.StatusCode)
	}
	defer res.Body.Close()

	var r ServiceIndex
	if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
		return nil, err
	}
	return &r, nil
}

I'm not very familiar with go, so I might be wrong about the code part, but using HTTP for nexus repositories will not work, according to https://stackoverflow.com/questions/68370067/gradle-error-when-deploying-to-nexus-repository which explains the error.

When using the NuGet CLI manually, I can successfully push to the repository.

In the resource, I am providing a URI with HTTPS, so there's no wrong configuration on my side.
The API key is the same that I used manually in CLI.

Also, is this project still alive? There hasn't been much activity since years.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.