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 Nov 15, 2023
1 parent f1ec281 commit 9bf282c
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 52 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 @@ -40,3 +40,4 @@ client/asset/eth/cmd/getgas/getgas
client/asset/eth/cmd/deploy/deploy
client/cmd/dexc-desktop/pkg/installers
server/noderelay/cmd/sourcenode/sourcenode
client/cmd/dexc-desktop/snap/snapcraft.yaml
22 changes: 20 additions & 2 deletions client/cmd/dexc-desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,29 @@ The dexc-desktop client is a cross-platform desktop application for the DEX clie
## Debian
Build with `./pkg/pkg-debian.sh`. The deb archive is located in **./build**.

For development, you'll need to install the WebKit Development Libraries.
`apt install libgtk-3-dev libwebkit2gtk-4.0-dev`
For development, you'll need to install the WebKit Development Libraries and the
standard build toolchain:

```bash
apt 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
The Snap package can be built on an Ubuntu system using Snapcraft, which can
be installed with `apt-get install snapcraft`. Then run `./pkg/pkg-snap.sh`,
which will build the snap package in **./build**. Note that this is dependent on
the Debian package so be sure to run the deb build first.

The snap can be uploaded to the Snap Store using `./pkg/upload-snap.sh`, after this
the package can be installed on any Ubuntu system using `snap install dexc`.

Prerequsities:
```bash
apt-get install snapcraft
```

## 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.
Expand Down
2 changes: 1 addition & 1 deletion client/cmd/dexc-desktop/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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/dexc-desktop/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,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
10 changes: 10 additions & 0 deletions client/cmd/dexc-desktop/metainfo/org.decred.dcrdex.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Desktop Entry]
Version=1.0
Type=Application
Name=Decred DEX Client
Comment=Multi-wallet backed by Decred DEX
Categories=Office;Finance;
Icon=org.decred.dcrdex
Exec=dexc
Terminal=false
StartupWMClass=DCRDEX
30 changes: 30 additions & 0 deletions client/cmd/dexc-desktop/metainfo/org.decred.dcrdex.metainfo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>org.decred.dcrdex</id>
<launchable type="desktop-id">org.decred.dcrdex.desktop</launchable>
<name>DCRDEX</name>
<summary>Decentralized cryptocurrency exchange</summary>
<metadata_license>MIT</metadata_license>
<project_license>BlueOak-1.0.0</project_license>
<url type="homepage">https://dex.decred.org</url>
<url type="help">https://chat.decred.org/#/room/#dex:decred.org</url>
<developer_name>The Decred Developers</developer_name>
<description>
<p>
Non-custodial peer-to-peer exchange where your funds never leave your wallet.
Trade Bitcoin, USDC, Ethereum, Decred, Dogecoin, Zcash and more without KYC
and fees, using atomic swaps technology.
</p>
</description>
<screenshots>
<screenshot type="default">
<image>https://raw.githubusercontent.com/decred/umbrel-app-store/master/decred-dcrdex/images/screenshot_1.png</image>
</screenshot>
<screenshot>
<image>https://raw.githubusercontent.com/decred/umbrel-app-store/master/decred-dcrdex/images/screenshot_2.png</image>
</screenshot>
<screenshot>
<image>https://raw.githubusercontent.com/decred/umbrel-app-store/master/decred-dcrdex/images/screenshot_3.png</image>
</screenshot>
</screenshots>
</component>
19 changes: 19 additions & 0 deletions client/cmd/dexc-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="dexc"
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}"

70 changes: 23 additions & 47 deletions client/cmd/dexc-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="dexc"
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 dexc binary.
BIN_TARGETDIR="/usr/lib/dexc"
BIN_TARGETDIR="/usr/bin"
BIN_BUILDDIR="${DEB_DIR}${BIN_TARGETDIR}"
BIN_FILENAME="${APP}"
BIN_BUILDPATH="${BIN_BUILDDIR}/${BIN_FILENAME}"

ICON_FILENAME="dexc.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,10 @@ DOT_DESKTOP_BUILDDIR="${DEB_DIR}${DOT_DESKTOP_TARGETDIR}"
DOT_DESKTOP_FILENAME="dexc.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 dexc
LDFLAGS="-s -w -X main.Version=${VER}${META:++${META}}"
Expand All @@ -83,40 +60,39 @@ 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}/dexc.svg"
install -Dm644 -t "${ICON_BUILDDIR}/128x128/apps" "${SRC_DIR}/dexc.png"
install -Dm644 -t "${ICON_BUILDDIR}/symbolic/apps" "${SRC_DIR}/dexc-symbolic.svg"

# AppStream metadata
# https://wiki.debian.org/AppStream
install -Dm644 -t "${DEB_DIR}/usr/share/metainfo" "${SRC_DIR}/org.decred.dcrdex.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.0
Name=Decred DEX Client
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/dexc-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/dexc-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

0 comments on commit 9bf282c

Please sign in to comment.