Skip to content

Commit

Permalink
Merge a28b327 into e0f7600
Browse files Browse the repository at this point in the history
  • Loading branch information
adferrand committed Oct 14, 2018
2 parents e0f7600 + a28b327 commit 4261fb8
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,11 @@ Certbot adheres to [Semantic Versioning](http://semver.org/).
### Added

* `revoke` accepts `--cert-name`, and doesn't accept both `--cert-name` and `--cert-path`.
* Create a build process to generate a self-contained NSIS installer for Certbot on Windows.
Once installed, two things are provided: a Windows shortcut opens a CMD with the necessary
privileged rights and a prompt and the `certbot` CLI is exposed to the CMD PATH.
* Add a continuous delivery pipeline to publish the relevant Certbot Windows
installer to GitHub when a new version of Certbot is realised.

### Changed

Expand Down
28 changes: 26 additions & 2 deletions appveyor.yml
@@ -1,12 +1,36 @@
# AppVeyor CI pipeline, executed on Windows Server 2016/2012 R2
image:
# => Windows Server 2012 R2
- Visual Studio 2015
# => Windows Server 2016
- Visual Studio 2017

branches:
only:
- master
- /^\d+\.\d+\.x$/ # version branches like X.X.X
- /^\d+\.\d+\.x$/ # Version branches like 0.28.x
- /^v\d+\.\d+\.\d+$/ # Version tags like v0.28.1
- /^test-.*$/

build: off

test_script:
- ps: Write-Host "Hello, world!"


# If deploy is needed, installer executable is constructed and published as artifact
before_deploy:
- ps: .\windows-installer\construct.ps1
- ps: Get-ChildItem .\windows-installer\build\nsis\*.exe | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }

# Deploy the installer to the relevant GitHub release
deploy:
provider: GitHub
tag: $(APPVEYOR_REPO_TAG_NAME)
release: Certbot $(APPVEYOR_REPO_TAG_NAME)
description: Release of Certbot $(APPVEYOR_REPO_TAG_NAME)
auth_token:
secure: wFtJuuyI4gizhyEAWbAFqkj2yivgcSKiMWIdfoPpHWhPktiU5C2I/bH8ZurcsDbn
artifact: /.*\.exe/
on:
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
APPVEYOR_REPO_TAG: true
1 change: 1 addition & 0 deletions windows-installer/.gitignore
@@ -0,0 +1 @@
build
Binary file added windows-installer/certbot.ico
Binary file not shown.
97 changes: 97 additions & 0 deletions windows-installer/construct.ps1
@@ -0,0 +1,97 @@
#Requires -RunAsAdministrator

"### Gather runtime data ###"

Try {
$chocoExe = Get-Command choco -errorAction Stop
} Catch {
"Error: Chocolatey (https://chocolatey.org/) needs to be installed to run this script."
Exit
}

Try {
$pythonExe = Get-Command py -errorAction Stop
} Catch {
Try {
$pythonExe = Get-Command python -errorAction Stop
} Catch {
"Error: Could not find the Python executable. Python for Windows is installed ?"
}
}

$script_path = $PSCommandPath
$repo_path = $script_path -replace "\\windows-installer\\construct\.ps1$"
$build_path = "$repo_path\windows-installer\build"

$venv_path = "$build_path\venv-config"
$installer_cfg_path = "$build_path\installer.cfg"
$wheels_path = "$build_path\wheels"

Push-Location $repo_path; $certbot_version = py -c "import certbot; print(certbot.__version__)"; Pop-Location

$certbot_packages = @("acme", "certbot")
$certbot_packages += Get-ChildItem "$repo_path\certbot-dns-*" | Where-Object { $_.PSIsContainer } | Foreach-Object { $_.Name }

"### Copy assets ###"

New-Item $build_path -ItemType directory -ErrorAction Ignore | Out-Null
Copy-Item -Path "$repo_path\windows-installer\certbot.ico" -Destination $build_path -Force
Copy-Item -Path "$repo_path\windows-installer\run_cmd.py" -Destination $build_path -Force

"### Prepare pynsist config ###"

"
[Application]
name=Certbot
version=$certbot_version
icon=certbot.ico
script=run_cmd.py
[Build]
directory=nsis
installer_name=certbot-$certbot_version-win32_install.exe
[Python]
version=3.7.0
[Include]
local_wheels=wheels\*.whl
[Command certbot]
entry_point=certbot.main:main
" | Set-Content -Path $installer_cfg_path

"### Prepare build environment ###"

Invoke-Expression "& '$pythonExe' -m venv --clear $venv_path"
Invoke-Expression "& '$chocoExe' upgrade -y nsis"

Push-Location $venv_path
.\Scripts\Activate.ps1
python -m pip install --upgrade pip
Pop-Location

Remove-Item -Recurse -Force -ErrorAction Ignore -Path $wheels_path
New-Item $wheels_path -ItemType directory | Out-Null
pip install wheel

# This code block can be replaced with 'pip install pynsist' when a new pynsist version
# will be pushed to pypi that integrates the work refered in takluyver/pynsist#166.
pip install flit
git clone https://github.com/takluyver/pynsist.git --branch distlib-launchers "$venv_path\pynsist"
Push-Location "$venv_path\pynsist"; flit install; Pop-Location

"### Compile wheels ###"

$wheels_projects = $certbot_packages -replace "^certbot$" | ForEach-Object {"$repo_path\$_"}
pip wheel $wheels_projects -w $wheels_path

"### Build the installer ###"

Push-Location $build_path
pynsist $installer_cfg_path
Pop-Location

"### Clean environment ###"

deactivate
20 changes: 20 additions & 0 deletions windows-installer/run_cmd.py
@@ -0,0 +1,20 @@
"""Start a cmd in a new window, with admin rights (required by Certbot to create symlinks)"""
import subprocess
import ctypes
import sys

def main():
if ctypes.windll.shell32.IsUserAnAdmin():
# Already with admin rights, run directly cmd
subprocess.Popen('start /wait cmd /k "'
' echo +---------------------------------------------------------------+'
'& echo ^# Welcome to Certbot. ^#'
'& echo ^# Please type \'certbot --help\' to find every available actions. ^#'
'& echo +---------------------------------------------------------------+"',
shell=True)
else:
# No admin rights, invoke again this script with an admin rights request
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)

if __name__ == '__main__':
main()

0 comments on commit 4261fb8

Please sign in to comment.