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

Distributing the Module as a Docker Image #1580

Closed
shurick81 opened this issue Jan 31, 2022 · 13 comments
Closed

Distributing the Module as a Docker Image #1580

shurick81 opened this issue Jan 31, 2022 · 13 comments
Labels
enhancement New feature or request

Comments

@shurick81
Copy link
Contributor

Is your feature request related to a problem? Please describe.

As a developer working with a multitude of projects where PnP.Powershell is used, I would like to be able to quickly run the module without the need of actually installing the module in the host environment so that I have isolated and repeatable experience of using the module for multiple different project.

Describe the solution you'd like

Every time when a new version of the PnP.PowerShell module is released, we could

  1. build a new a new version of the Docker image with the module installed.

I tried the following Dockerfile locally and it works quite fine for me so far:

FROM mcr.microsoft.com/powershell:7.2.1-alpine-3.14-20211215

RUN pwsh -c "Install-Module -Name PnP.PowerShell -RequiredVersion 1.9.0 -Force"
  1. do some testing of the new module version working inside a container
  2. publish the image to https://hub.docker.com/u/m365pnp

Describe alternatives you've considered

Alternatively we could just come up with a small guide/demo/webinar that shows how to build and use a local image, since there is no published one.

Additional context

We wanted to consider this improvement when the module GA is close enough, but then this issue was forgotten I believe:
#11

@shurick81 shurick81 added the enhancement New feature or request label Jan 31, 2022
@KoenZomers
Copy link
Collaborator

@shurick81 I have no such experience myself to be able to set this up. Would you be able to do this?

@shurick81
Copy link
Contributor Author

@KoenZomers yes, I would love to do it. First of all we could discuss some more specific use cases here in this thread and then I could come up with a PR.

@KoenZomers
Copy link
Collaborator

Nice. I think you mention one yourself already in your start post. I could envision having a docker image per version perhaps to test things in a specific version? Not a docker guy here so not sure if that makes sense.

@shurick81
Copy link
Contributor Author

I suggest that if we go with docker image, we need to extend the use cases.

  1. to quickly run the module without the need of actually installing the module in the host environment so that I have isolated and repeatable experience of using the module for multiple different projects
  2. to access local host directories through using volumes on a docker container
  3. to use image for running jobs in such pipeline engines like Azure DevOps (maybe in GitLab also)

What do you think?

@shurick81
Copy link
Contributor Author

Here's a preliminary result:

  1. nightly releases example: https://hub.docker.com/repository/docker/asapozhkov/pnp-powershell
  2. Build and publish nightly releases: https://github.com/alexsapozhkov/powershell/tree/dev/docker
  3. Build and publish via Github Actions: https://github.com/alexsapozhkov/powershell/actions/workflows/nightlyrelease.yml

@shurick81
Copy link
Contributor Author

shurick81 commented Mar 14, 2022

The easiest way to try it out if you have Docker installed:

docker run --rm asapozhkov/powershell:nightly pwsh -c "Get-Module PnP.PowerShell -ListAvailable"

@shurick81
Copy link
Contributor Author

I can see that in the m365pnp organization in Docker Hub, there are already a few images:

  • m365pnp/spfx
  • m365pnp/cli-microsoft365

Do you think it is fine if we name the image m365pnp/powershell?

@shurick81
Copy link
Contributor Author

Do we need this container runnable on ARM platform?

@shurick81
Copy link
Contributor Author

Here's how you could currently try it out:

docker run --rm -it asapozhkov/powershell pwsh -c "Get-Module PnP.PowerShell -ListAvailable"

Also tested (in Linux at least) that it is possible to manipulate with files on the host using commands in a container:

docker run --rm -it -v $(pwd):/home/powershell asapozhkov/powershell pwsh -c "cd /home/powershell; Get-ChildItem"
docker run --rm -it -v $(pwd):/home/powershell asapozhkov/powershell pwsh -c "cd /home/powershell; Set-Content test test"

@shurick81
Copy link
Contributor Author

Here's the commit so far: dev...alexsapozhkov:dev

@shurick81
Copy link
Contributor Author

PR: #1794

gautamdsheth pushed a commit that referenced this issue May 22, 2022
* building docker image in workflows

* ls

* cd dev

* checkout

* removing debug output

* nightly version

* docker login

* docker secret

* pushing to docker hub

* docker readme

* using DOCKER_USERNAME and DOCKER_PASSWORD

* using DOCKER_USERNAME and DOCKER_PASSWORD

* adding nightly tag

* verified adding nightly tag

* corrected user name ref

* run via schedule again

* more specific job name

* divided job into simpler steps

* testing pipeline for publishing

* preparing for linux containers

* triggering on yaml change

* password in quoutes

* testing publishing script with parameters

* no ` needed for pwsh jobs

* Getting docker tags via Invoke-RestMethod

* show every unpublished image

* fixed version comparisons

* publishin all not prereleases

* safer manipulating with :

* replacing quotes

* universal docker file

* using universal dockerfile instead of special

* listing published images with 10k limit

* release only running via schedule

* updated base image version

* cleaning nightly release before merging to origin

* typo in yaml cleaning

* removing unused file

* removing unused file

* removing old files

* new line at end of file

* more documentation for manual publishing

* removing unneccessary (so far) documentation

* publishing image for 5 platform

* fixing parameters in github actions

* typo in space

* sticking to 1 dockerfile

* altering installation user

* 3 platforms for Windows is default

* fixed string comparison

* removing unnecessary quotes

* fixed logical comparison

* specifying platform for building

* using buildx for arm32v7-ubuntu-bionic

* buildx debug output

* buildx build --load

* removing arm image

* keeping 3 platforms

* publishing latest for only linux

* nightly release for 3 platforms

* replacing with a fake job

* using PS syntax for Windows builder

* fixing more PS syntax in pipeline

* returning back the module publishing steps

* installing module for all the users

* outputting module list after installing

* installing module for all the users

* installing for all users in Linux

* removing arm image from docu

* more user documentation

* removed unused space in the dockerfile

* reference to the PS gallery for versions

* correcting the pnp organization name in Docker
@shurick81
Copy link
Contributor Author

I guess we are done here?

@KoenZomers
Copy link
Collaborator

Yep seems like it :) Thanks for your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants