Skip to content

Commit

Permalink
Merge pull request #14540 from anjannath/pkginstaller
Browse files Browse the repository at this point in the history
Add support for building macOS pkg installer
  • Loading branch information
openshift-merge-robot authored Jul 27, 2022
2 parents 4277b1f + c35ae76 commit 5397a00
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 0 deletions.
6 changes: 6 additions & 0 deletions contrib/pkginstaller/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
out
Distribution
welcome.html
tmp-download
.vscode
root
17 changes: 17 additions & 0 deletions contrib/pkginstaller/Distribution.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<installer-script minSpecVersion="1.000000">
<title>Podman __VERSION__</title>
<background mime-type="image/png" file="banner.png" scaling="proportional"/>
<welcome file="welcome.html" mime-type="text/html" />
<conclusion file="conclusion.html" mime-type="text/html" />
<license file="LICENSE.txt"/>
<options customize="never" hostArchitectures="x86_64,arm64" />
<domains enable_localSystem="true" />
<choices-outline>
<line choice="podman"/>
</choices-outline>
<choice id="podman" title="podman">
<pkg-ref id="podman.pkg"/>
</choice>
<pkg-ref id="podman.pkg">podman.pkg</pkg-ref>
</installer-script>
50 changes: 50 additions & 0 deletions contrib/pkginstaller/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
SHELL := bash

ARCH ?= aarch64
PODMAN_VERSION ?= 4.1.0
GVPROXY_VERSION ?= 0.4.0
QEMU_VERSION ?= 7.0.0-2
GVPROXY_RELEASE_URL ?= https://github.com/containers/gvisor-tap-vsock/releases/download/v$(GVPROXY_VERSION)/gvproxy-darwin
QEMU_RELEASE_URL ?= https://github.com/containers/podman-machine-qemu/releases/download/v$(QEMU_VERSION)/podman-machine-qemu-$(ARCH)-$(QEMU_VERSION).tar.xz
PACKAGE_DIR ?= out/packaging
TMP_DOWNLOAD ?= tmp-download
PACKAGE_ROOT ?= root

default: pkginstaller

get_gvproxy:
mkdir -p $(TMP_DOWNLOAD)
cd $(TMP_DOWNLOAD) && curl -sLo gvproxy $(GVPROXY_RELEASE_URL)

get_qemu:
mkdir -p $(TMP_DOWNLOAD)
cd $(TMP_DOWNLOAD) && curl -sLO $(QEMU_RELEASE_URL)

packagedir: package_root Distribution welcome.html
mkdir -p $(PACKAGE_DIR)
cp -r Resources $(PACKAGE_DIR)/
cp welcome.html $(PACKAGE_DIR)/Resources/
cp Distribution $(PACKAGE_DIR)/
cp -r scripts $(PACKAGE_DIR)/
cp -r $(PACKAGE_ROOT) $(PACKAGE_DIR)/
cp package.sh $(PACKAGE_DIR)/
cd $(PACKAGE_DIR) && pkgbuild --analyze --root ./root component.plist
echo -n $(PODMAN_VERSION) > $(PACKAGE_DIR)/VERSION
echo -n $(ARCH) > $(PACKAGE_DIR)/ARCH
cp ../../LICENSE $(PACKAGE_DIR)/Resources/LICENSE.txt

package_root: get_gvproxy get_qemu
mkdir -p $(PACKAGE_ROOT)/podman/bin $(PACKAGE_ROOT)/podman/qemu
tar -C $(PACKAGE_ROOT)/podman/qemu -xf $(TMP_DOWNLOAD)/podman-machine-qemu-$(ARCH)-$(QEMU_VERSION).tar.xz
cp $(TMP_DOWNLOAD)/gvproxy $(PACKAGE_ROOT)/podman/bin/
chmod a+x $(PACKAGE_ROOT)/podman/bin/*

%: %.in
@sed -e 's/__VERSION__/'$(PODMAN_VERSION)'/g' $< >$@

pkginstaller: packagedir
cd $(PACKAGE_DIR) && ./package.sh ..

.PHONY: clean
clean:
rm -rf $(TMP_DOWNLOAD) $(PACKAGE_ROOT) $(PACKAGE_DIR) Distribution welcome.html
22 changes: 22 additions & 0 deletions contrib/pkginstaller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## How to build

```sh
$ make ARCH=<amd64 | aarch64> NO_CODESIGN=1 pkginstaller

# or to create signed pkg
$ make ARCH=<amd64 | aarch64> CODESIGN_IDENTITY=<ID> PRODUCTSIGN_IDENTITY=<ID> pkginstaller
```

The generated pkg will be written to `out/podman-macos-installer-*.pkg`.
Currently the pkg installs `podman`, `qemu`, `gvproxy` and `podman-mac-helper` to `/Applications/podman`

The `qemu` build it uses is from [containers/podman-machine-qemu](https://github.com/containers/podman-machine-qemu)

## Uninstalling

```sh
$ sudo rm -rf /opt/podman
```

### Screenshot
<img width="626" alt="screenshot-macOS-pkg-podman" src="https://user-images.githubusercontent.com/8885742/157380992-2e3b1573-34a0-4aa0-bdc1-a85f4792a1d2.png">
Binary file added contrib/pkginstaller/Resources/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions contrib/pkginstaller/Resources/conclusion.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
</head>
<body>
<div align="left" style="font-family: Helvetica; padding-left: 10px;">
<br/>
<p style="color: #020202; font-size: 12px;">Thanks for installing Podman!</p>
<p style="color: #020202; font-size: 12px;">You can now start using the 'podman' command. First run 'podman machine init'</b>.</p>
</div>
</body>
</html>
60 changes: 60 additions & 0 deletions contrib/pkginstaller/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

set -euxo pipefail

BASEDIR=$(dirname "$0")
OUTPUT=$1
CODESIGN_IDENTITY=${CODESIGN_IDENTITY:-mock}
PRODUCTSIGN_IDENTITY=${PRODUCTSIGN_IDENTITY:-mock}
NO_CODESIGN=${NO_CODESIGN:-0}
HELPER_BINARIES_DIR="/opt/podman/qemu/bin"

binDir="${BASEDIR}/root/podman/bin"

function build_podman() {
pushd "$1"
make podman-remote HELPER_BINARIES_DIR="${HELPER_BINARIES_DIR}"
make podman-mac-helper
cp bin/darwin/podman "contrib/pkginstaller/out/packaging/${binDir}/podman"
cp bin/darwin/podman-mac-helper "contrib/pkginstaller/out/packaging/${binDir}/podman-mac-helper"
popd
}

function sign() {
if [ "${NO_CODESIGN}" -eq "1" ]; then
return
fi
local opts=""
entitlements="${BASEDIR}/$(basename "$1").entitlements"
if [ -f "${entitlements}" ]; then
opts="--entitlements ${entitlements}"
fi
codesign --deep --sign "${CODESIGN_IDENTITY}" --options runtime --force --timestamp "${opts}" "$1"
}

version=$(cat "${BASEDIR}/VERSION")
arch=$(cat "${BASEDIR}/ARCH")

build_podman "../../../../"
sign "${binDir}/podman"
sign "${binDir}/gvproxy"
sign "${binDir}/podman-mac-helper"

pkgbuild --identifier com.redhat.podman --version "${version}" \
--scripts "${BASEDIR}/scripts" \
--root "${BASEDIR}/root" \
--install-location /opt \
--component-plist "${BASEDIR}/component.plist" \
"${OUTPUT}/podman.pkg"

productbuild --distribution "${BASEDIR}/Distribution" \
--resources "${BASEDIR}/Resources" \
--package-path "${OUTPUT}" \
"${OUTPUT}/podman-unsigned.pkg"
rm "${OUTPUT}/podman.pkg"

if [ ! "${NO_CODESIGN}" -eq "1" ]; then
productsign --timestamp --sign "${PRODUCTSIGN_IDENTITY}" "${OUTPUT}/podman-unsigned.pkg" "${OUTPUT}/podman-installer-macos-${arch}.pkg"
else
mv "${OUTPUT}/podman-unsigned.pkg" "${OUTPUT}/podman-installer-macos-${arch}.pkg"
fi
27 changes: 27 additions & 0 deletions contrib/pkginstaller/scripts/postinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -e

BZSH_PODMAN_PATH_EXP='PATH="/opt/podman/bin:$PATH"'
FISH_PODMAN_PATH_EXP='set PATH "/opt/podman/bin $PATH"'
BASHRC_PATH="$HOME/.bash_profile"
ZSHENV_PATH="$HOME/.zshenv"
ZSHRC_PATH="$HOME/.zshrc"
FSHCFG_PATH="$HOME/.config/fish/config.fish"

# append /Applications/podman/bin to $PATH
if [ -f "$BASHRC_PATH" ]; then
grep -Fxq "$BZSH_PODMAN_PATH_EXP" "$BASHRC_PATH" || echo "$BZSH_PODMAN_PATH_EXP" >> "$BASHRC_PATH"
fi
if [ -f "$ZSHENV_PATH" ]; then
grep -Fxq "$BZSH_PODMAN_PATH_EXP" "$ZSHENV_PATH" || echo "$BZSH_PODMAN_PATH_EXP" >> "$ZSHENV_PATH"
fi
if [ -f "$ZSHRC_PATH" ]; then
grep -Fxq "$BZSH_PODMAN_PATH_EXP" "$ZSHRC_PATH" || echo "$BZSH_PODMAN_PATH_EXP" >> "$ZSHRC_PATH"
fi
if [ -f "$FSHCFG_PATH" ]; then
grep -Fxq "$FISH_PODMAN_PATH_EXP" "$FSHCFG_PATH" || echo "$FISH_PODMAN_PATH_EXP" >> "$FSHCFG_PATH"
fi

ln -s /opt/podman/bin/podman-mac-helper /opt/podman/qemu/bin/podman-mac-helper
ln -s /opt/podman/bin/gvproxy /opt/podman/qemu/bin/gvproxy
5 changes: 5 additions & 0 deletions contrib/pkginstaller/scripts/preinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

rm -rf /opt/podman
16 changes: 16 additions & 0 deletions contrib/pkginstaller/welcome.html.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
</head>
<body>
<div align="left" style="font-family: Helvetica; padding-left: 10px;">
<br/>
<p style="color: #020202; font-size: 12px;">This will install <span style="color: #46b9d6; font-size: 12px;">Podman __VERSION__</span>
on your computer. You will be guided through the steps necessary to install this software.</p>
<br/>
<p style="color: #abb0b0; font-size: 12px;">Click <span style="color: #626666">“Continue"</span> to continue the
setup</p>
</div>
</body>
</html>

0 comments on commit 5397a00

Please sign in to comment.