Showing posts with label Github. Show all posts
Showing posts with label Github. Show all posts

Wednesday, September 20, 2023

Use Github secrets to restore nuget packages from private packages source with authentication in Dockerfile via Github actions

If you use private nuget packages source with authentication and Docker in your project you may need to restore packages from this custom packages source within Docker file. In this post I will show how to use Github secrets for that when you build Docker image via docker/build-push-action Github action.

First of all in the yaml file of our Github action we need to pass necessary secrets references to the build action using the following syntax:

name: Build
id: docker_build
uses: docker/build-push-action@v5
with:
  ...
  secrets: |
    "NUGET_USERNAME=${{ secrets.NUGET_USERNAME }}"
    "NUGET_PWD=${{ secrets.NUGET_PWD }}"

After that in Docker file we fetch passed secrets (they are stored to special files under /run/secrets/... path which is available during Docker image build) and will store them to environment variables using export command. After that we will add our private packages source with username and password (using dotnet nuget add source). When it will be done we will be able to run "dotnet restore" command which will restore project dependencies including those which come from private nuget source:

COPY Foo.csproj src/

RUN --mount=type=secret,id=NUGET_USERNAME \
	--mount=type=secret,id=NUGET_PWD \
	export NUGET_USERNAME=$(cat /run/secrets/NUGET_USERNAME) && \
	export NUGET_PWD=$(cat /run/secrets/NUGET_PWD) && \
	dotnet nuget add source https://my-private-packages-source/index.json --name FooPackages --username "${NUGET_USERNAME}" --password "${NUGET_PWD}" --store-password-in-clear-text

RUN dotnet restore "src/Foo.csproj" /p:IsDockerBuild=true

Note that it is important to pipe commands which export environment variables and then use them to the same single RUN command. If you will try to use these variables in separate RUN command "nuget add source" will tell that "Package source with Name: ... added successfully" but then you will get confusing error when will try to run "dotnet restore":

Error NU1301: Unable to load the service index for source

But if everything is done in the way how it is described above then your project dependencies should be restored successfully for your Docker image.

Thursday, January 25, 2018

OfficeDevPnP classes and methods reference

Office 365 Developers Patterns and Practices library contains many useful methods for Sharepoint Online development. I would like to have some kind of reference page which would contain all methods from this doclib in one place so I can search them by Ctrl-F without pagination. In order to do such reference I used NDepend tool and built report from OfficeDevPnP.Core.dll v.2.22.1801.0 which is currently latest version for Sharepoint Online (note that for on-premise there is separate assembly). NDepend has useful feature called Code Query Linq (CQLinq) which allows you to make queries to the code in loaded assemblies, i.e. work with code as it would be data. E.g. for getting all methods with their parent classes I used the following Linq query:

   1: from m in Application.Methods
   2: let t = m.ParentType
   3: where !t.IsGeneratedByCompiler && !m.IsClassConstructor && !m.IsConstructor
   4: select new { m.ParentType, m }

After that exported report to Excel where added some formatting and saved to GitHub gist: https://gist.github.com/sadomovalex/74dc733c2b8a9a07a2ab23b7de705bf5.

You may use this gist as your reference for OfficeDevPnP as well.

Wednesday, September 27, 2017

Camlex has been moved to Github

Some time ago MS announced Codeplex shutdown in 2017. I personally liked Codeplex – all these years which it was used for hosting Camlex project I was quite satisfied with its services and functionality. But time goes on and MS made this decision which we have to live with. Regardless of Codeplex shutdown Camlex development will be continued and I’m glad to announce that it was migrated to Github. So the new project home is https://github.com/sadomovalex/camlex. Earlier when project was hosted on Codeplex there were 3 choices how to get ready for use .Net assembly:

  • download it from Codeplex
  • install it directly in VS from Nuget (Camlex.NET.dll package for basic server object model and Camlex.Client.dll for client object model)
  • get latest source code and compile project in VS

After migration to Github Nuget will be primary way of getting binaries and of course it will be still possible to get source code and compile it in VS (project will be remain open source with the same Ms-Pl license). Issues and discussions were migrated together with source code and documentation (discussions were migrated as closed issues to Github with “Discussion: ” prefix: Migrate issues and discussions from Codeplex to Github). So let’s continue Camlex journey with the new home and will add more value to it already on Github.

Tuesday, September 26, 2017

Migrate issues and discussions from Codeplex to Github

As you probably know Codeplex will be shut down soon. I used Codeplex many years for hosting Camlex project – open source library for creating dynamic CAML queries for Sharepoint by C# lambda expressions. Migration guide available on Codeplex says how to move source code to the Github, but unfortunately it doesn’t mention how to move issues and discussions. In this post I will share my experience of how to migrate issues and discussions from Codeplex to Github.

For migrating issues I used Codeplex-Issues-Importer Python script which worked quite well: it added issues with Codeplex label and closed those issues which were closed on Codeplex. But for discussions it was not so straightforward. First of all in Github there are no such thing as “discussion” as in Codeplex, so I decided to move them to Github issues with “Discussion: [Title]” prefix. In order to perform migration itself I made fork of Codeplex-Issues-Importer and modified it so it started to parse Codeplex discussions instead of issues and then save them into Github as issue. Fork can be found here: https://github.com/sadomovalex/Codeplex-Issues-Importer. Script is not perfect but probably will be enough just for keeping old discussions in migrated project. Result of migration can be checked here: https://github.com/sadomovalex/camlex/issues?page=2&q=is%3Aissue+is%3Aclosed.