Skip to content

Commit

Permalink
Implemented snap package build
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzen committed May 27, 2024
1 parent e8dc621 commit 45de6fc
Show file tree
Hide file tree
Showing 14 changed files with 800 additions and 61 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

## Build and Publish Snap Package workflow

This workflow builds a `snap` package and uploads it to the [Snap Store](https://snapcraft.io/store). It has a `workflow_dispatch` trigger so it can be triggered manually only, it is not hooked up to any other GH event.

The store upload requires the `SNAPCRAFT_STORE_CREDENTIALS` variable to be set in [Github Secrets](https://github.com/decred/dcrdex/settings/secrets/actions).
See https://github.com/snapcore/action-publish for details.
48 changes: 48 additions & 0 deletions .github/workflows/build-snap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and Publish Snap Package

on:
# manually trigger the workflow from the Actions tab
workflow_dispatch:

jobs:
build-snap:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
fetch-depth: 0

- name: Compile frontend
working-directory: client/webserver/site
run: |
npm install
npm run build
- name: Install deb deps
run: |
sudo apt-get update
sudo apt-get -y install libgtk-3-dev libwebkit2gtk-4.0-dev build-essential
- name: Build deb package
working-directory: client/cmd/dexc-desktop
run: pkg/pkg-debian.sh

- name: Prepare snapcraft.yml
working-directory: client/cmd/dexc-desktop
run: pkg/prepare-snap.sh

- name: Build snap package
uses: snapcore/action-build@2ee46bc29d163c9c836f2820cc46b39664bf0de2 # v1.1.3
id: build
with:
path: client/cmd/dexc-desktop

- name: Publish snap to Snap Store
uses: snapcore/action-publish@0a8d537ae06f4a292e8b4ef1084cd5631b3c6871 # v1.1.1
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}
with:
snap: ${{ steps.build.outputs.snap }}
release: stable
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ client/cmd/bisonw-desktop/pkg/installers
client/cmd/testbinance/testbinance
client/cmd/mmbaltracker/mmbaltracker
server/noderelay/cmd/sourcenode/sourcenode
client/cmd/dexc-desktop/snap/snapcraft.yaml
tatanka/cmd/demo/demo
server/cmd/validatemarkets
client/cmd/translationsreport/translationsreport
Expand Down
57 changes: 46 additions & 11 deletions client/cmd/bisonw-desktop/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,53 @@
# Build Instructions for dexc-desktop
# Build Instructions for bisonw-desktop

The dexc-desktop client is a cross-platform desktop application for the DEX client and wallet. The instructions below are for building the client from source. If you are looking for pre-built binaries, see the [releases page](https://github.com/decred/dcrdex/releases).
The bisonw-desktop client is a cross-platform desktop application for the DEX client and wallet. The instructions below are for building the client from source. If you are looking for pre-built binaries, see the [releases page](https://github.com/decred/dcrdex/releases).

**Note**: The instructions below are to be run in your CLI from the `dexc-desktop` directory.
**Note**: The instructions below are to be run in your CLI from the `client/cmd/bisonw-desktop` directory.

## Debian
Build with `./pkg/pkg-debian.sh`. The deb archive is located in **./build**.
Build with `./pkg/pkg-debian.sh`. The deb archive will be located in **./build**.

For development, you'll need to install the WebKit Development Libraries and the standard build toolchain:

```bash
sudo apt-get install libgtk-3-dev libwebkit2gtk-4.0-dev build-essential
```
For production, they are specified as DEPENDS in the control file and the package manager will install them.

## Snap

Snap is a package standard that can be installed on many Linux distributions from the Snap Store, and via software centers in e.g. Fedora, Ubuntu.

### Preparing the build environment
```bash
# on Ubuntu 22.04 LTS:
sudo apt-get install snap
# on Debian:
sudo apt-get install snapd

sudo snap install --classic snapcraft
sudo adduser $USER lxd
newgrp lxd
lxd init --auto
sudo ufw disable # if ufw is installed on the host, this is neccessary for lxd to have network access

```

### Running the build

1. Build the Debian package
2. `./pkg/pkg-snap.sh`

### Installing the .snap file locally

`sudo snap install --dangerous build/bisonwallet*.snap`

### Publishing the snap

The snap can be uploaded to the Snap Store using `./pkg/publish-snap.sh`. This requires [Snapcraft developer account credentials](https://snapcraft.io/docs/releasing-your-app). After this is completed, the package can be installed on any system running `snap` by running `snap install bisonw`. The app will be available on the [Snap Store](https://snapcraft.io/store/bisonw).



For development, you'll need to install the WebKit Development Libraries.
`apt install libgtk-3-dev libwebkit2gtk-4.0-dev`
For production, they are specified as DEPENDS in the control file and the
package manager will install them.

## MacOS (darwin)
Build with `./pkg/pkg-darwin.sh` for `amd64` MacOS machines. If running on an
`arm64` machine, you'll need to build with `TARGETS=darwin/arm64 ./pkg/pkg-darwin.sh` instead.
The `.dmg` click installer can be located in **./pkg/installers** after a successful build.
Build with `./pkg/pkg-darwin.sh` for `amd64` MacOS machines. If running on an `arm64` machine, you'll need to build with `TARGETS=darwin/arm64 ./pkg/pkg-darwin.sh` instead. The `.dmg` click installer can be located in **./pkg/installers** after a successful build.
2 changes: 1 addition & 1 deletion client/cmd/bisonw-desktop/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ require (
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.3 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/decred/dcrd/dcrjson/v4 v4.0.1 // indirect
github.com/decred/dcrd/dcrutil/v4 v4.0.1 // indirect
github.com/decred/dcrd/dcrutil/v4 v4.0.2-0.20231005000813-c102e54b4128 // indirect
github.com/decred/dcrd/gcs/v4 v4.0.0 // indirect
github.com/decred/dcrd/hdkeychain/v3 v3.1.1 // indirect
github.com/decred/dcrd/lru v1.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions client/cmd/bisonw-desktop/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etly
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/decred/dcrd/dcrjson/v4 v4.0.1 h1:vyQuB1miwGqbCVNm8P6br3V65WQ6wyrh0LycMkvaBBg=
github.com/decred/dcrd/dcrjson/v4 v4.0.1/go.mod h1:2qVikafVF9/X3PngQVmqkbUbyAl32uik0k/kydgtqMc=
github.com/decred/dcrd/dcrutil/v4 v4.0.1 h1:E+d2TNbpOj0f1L9RqkZkEm1QolFjajvkzxWC5WOPf1s=
github.com/decred/dcrd/dcrutil/v4 v4.0.1/go.mod h1:7EXyHYj8FEqY+WzMuRkF0nh32ueLqhutZDoW4eQ+KRc=
github.com/decred/dcrd/dcrutil/v4 v4.0.2-0.20231005000813-c102e54b4128 h1:hDyaGr+CuE9M/fCC7raFGH89wPd49tnjuc4wftISwa4=
github.com/decred/dcrd/dcrutil/v4 v4.0.2-0.20231005000813-c102e54b4128/go.mod h1:7EXyHYj8FEqY+WzMuRkF0nh32ueLqhutZDoW4eQ+KRc=
github.com/decred/dcrd/gcs/v4 v4.0.0 h1:bet+Ax1ZFUqn2M0g1uotm0b8F6BZ9MmblViyJ088E8k=
github.com/decred/dcrd/gcs/v4 v4.0.0/go.mod h1:9z+EBagzpEdAumwS09vf/hiGaR8XhNmsBgaVq6u7/NI=
github.com/decred/dcrd/hdkeychain/v3 v3.1.1 h1:4WhyHNBy7ec6qBUC7Fq7JFVGSd7bpuR5H+AJRID8Lyk=
Expand Down
19 changes: 19 additions & 0 deletions client/cmd/bisonw-desktop/pkg/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

# This file defines common variables to be source'd by the various build scripts
# in this directory.

# pick up the release tag from git
VER=$(git describe --tags --abbrev=0 --always | sed -e 's/^v//')
META= # "release"
REV="0"

APP="bisonw"
ARCH="amd64"

# The build directory will be deleted at the beginning of every build. The
# directory is .gitignore'd.
BUILD_DIR="./build"

# DEB_NAME follows the prescribed format for debian packaging.
DEB_NAME="${APP}_${VER}-${REV}_${ARCH}"

76 changes: 29 additions & 47 deletions client/cmd/bisonw-desktop/pkg/pkg-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,12 @@
# A good getting-started guide for Debian packaging can be found at
# https://www.internalpointers.com/post/build-binary-deb-package-practical-guide

set -ex
# turn this on for debugging, keep noise low for prod builds
# set -ex

APP="bisonw"
VER="0.7.0-pre"
META= # "release"
REV="0"
ARCH="amd64"
source $(dirname "$0")/common.sh

# DEB_NAME follows the prescribed format for debian packaging.
DEB_NAME="${APP}_${VER}-${REV}_${ARCH}"

# The build directory will be deleted at the beginning of every build. The
# directory is .gitignore'd.
BUILD_DIR="./build"

# A directory for binary source files e.g. image files.
# A directory containing metadata files
SRC_DIR="./src"

# The DEB_DIR represents the root directory in our target system. The directory
Expand All @@ -36,16 +26,11 @@ POSTINST_PATH="${CONTROL_DIR}/postinst"
POSTRM_PATH="${CONTROL_DIR}/postrm"

# The bisonw binary.
BIN_TARGETDIR="/usr/lib/bisonw"
BIN_TARGETDIR="/usr/bin"
BIN_BUILDDIR="${DEB_DIR}${BIN_TARGETDIR}"
BIN_FILENAME="${APP}"
BIN_BUILDPATH="${BIN_BUILDDIR}/${BIN_FILENAME}"

ICON_FILENAME="bisonw.png"
SRC_TARGETDIR="${BIN_TARGETDIR}/src"
SRC_BUILDDIR="${DEB_DIR}${SRC_TARGETDIR}"
LIBICON_BUILDPATH="${SRC_BUILDDIR}/${ICON_FILENAME}"

# The Desktop Entry is a format for "installing" programs on Linux, creating
# an entry in the main menu.
# https://specifications.freedesktop.org/desktop-entry-spec/latest/
Expand All @@ -54,18 +39,17 @@ DOT_DESKTOP_BUILDDIR="${DEB_DIR}${DOT_DESKTOP_TARGETDIR}"
DOT_DESKTOP_FILENAME="bisonw.desktop"
DOT_DESKTOP_BUILDPATH="${DOT_DESKTOP_BUILDDIR}/${DOT_DESKTOP_FILENAME}"

# This will be the icon shown for the program in the taskbar. I know that both
# PNG and SVG will work. If it's a bitmap, should probably be >= 128 x 128 px.
ICON_TARGETDIR="/usr/share/pixmaps"
ICON_BUILDDIR="${DEB_DIR}${ICON_TARGETDIR}"
DESKTOPICON_BUILDPATH="${ICON_BUILDDIR}/${ICON_FILENAME}"

# Prepare the directory structure.
rm -fr "${BUILD_DIR}"
mkdir -p -m 0755 "${CONTROL_DIR}"
mkdir -p "${SRC_BUILDDIR}" # subdir of BIN_BUILDDIR
mkdir -p "${DOT_DESKTOP_BUILDDIR}"
mkdir -p "${ICON_BUILDDIR}"

# Build site bundle
CWD=$(pwd)
cd ../../webserver/site
npm clean-install
npm run build
cd $CWD

# Build bisonw
LDFLAGS="-s -w -X main.Version=${VER}${META:++${META}}"
Expand All @@ -83,40 +67,38 @@ Depends: libgtk-3-0, libwebkit2gtk-4.0-37
Description: A multi-wallet backed by Decred DEX
EOF

# Symlink the binary and update the desktop icons, refresh the "start" menu.
# Copy icons
# This will be the icon shown for the program in the taskbar. I know that both
# PNG and SVG will work. If it's a bitmap, should probably be >= 128 x 128 px.
ICON_TARGETDIR="/usr/share/icons/hicolor"
ICON_BUILDDIR="${DEB_DIR}${ICON_TARGETDIR}"
install -Dm644 -t "${ICON_BUILDDIR}/scalable/apps" "${SRC_DIR}/bisonw.svg"
install -Dm644 -t "${ICON_BUILDDIR}/128x128/apps" "${SRC_DIR}/bisonw.png"

# AppStream metadata
# https://wiki.debian.org/AppStream
install -Dm644 -t "${DEB_DIR}/usr/share/metainfo" "${SRC_DIR}/org.decred.bisonwallet.metainfo.xml"

# Update the desktop icons, refresh the "start" menu.
cat > "${POSTINST_PATH}" <<EOF
ln -s "${BIN_TARGETDIR}/${BIN_FILENAME}" "/usr/bin/${BIN_FILENAME}"
update-desktop-database
EOF
chmod 775 "${POSTINST_PATH}"

# Remove symlink from postinst.
cat > "${POSTRM_PATH}" <<EOF
rm "/usr/bin/${BIN_FILENAME}"
EOF
chmod 775 "${POSTRM_PATH}"

# Example file:
# https://specifications.freedesktop.org/desktop-entry-spec/latest/apa.html
cat > "${DOT_DESKTOP_BUILDPATH}" <<EOF
[Desktop Entry]
Version=${VER}
Version=1.5
Name=Bison Wallet
Comment=Multi-wallet backed by Decred DEX
Exec=${BIN_TARGETDIR}/${BIN_FILENAME}
Icon=${ICON_TARGETDIR}/${ICON_FILENAME}
Exec=${BIN_FILENAME}
Icon=${APP}
Terminal=false
Type=Application
Categories=Office;Development;
Categories=Office;Finance;
EOF
chmod 644 "${DOT_DESKTOP_BUILDPATH}"

# Icon
cp "${SRC_DIR}/${ICON_FILENAME}" "${DESKTOPICON_BUILDPATH}"
chmod 644 "${DESKTOPICON_BUILDPATH}"

cp "${SRC_DIR}/${ICON_FILENAME}" "${LIBICON_BUILDPATH}"
chmod 644 "${LIBICON_BUILDPATH}"

# Build the installation archive (.deb file).
dpkg-deb --build --root-owner-group "${DEB_DIR}"
14 changes: 14 additions & 0 deletions client/cmd/bisonw-desktop/pkg/pkg-snap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -ex

SCRIPT_DIR=$(dirname "$0")

source $SCRIPT_DIR/common.sh

SNAPCRAFT_YML_IN=snap/local/snapcraft.yaml.in
SNAPCRAFT_YML=snap/snapcraft.yaml
sed -e "s/\$VERSION/$VER/g" \
-e "s/\$DEB_NAME/$DEB_NAME/g" "$SNAPCRAFT_YML_IN" > "$SNAPCRAFT_YML"

snapcraft --verbose --output $BUILD_DIR/
7 changes: 7 additions & 0 deletions client/cmd/bisonw-desktop/pkg/publish-snap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

source $(dirname "$0")/common.sh

snapcraft login

snapcraft upload --release=stable $BUILD_DIR/${APP}_${VER}_${ARCH}.snap
Loading

0 comments on commit 45de6fc

Please sign in to comment.