Skip to content

Commit

Permalink
fix: build and embedded binary
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed May 8, 2024
1 parent 114d180 commit 4c54e8d
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 43 deletions.
6 changes: 6 additions & 0 deletions .changeset/fast-crabs-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'renterd': patch
'hostd': patch
---

Fixed an issue with the binary embedding.
2 changes: 2 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ runs:
node-version: ${{ inputs.node_version }}
registry-url: https://registry.npmjs.org
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'
cache-key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
- name: Install
run: yarn
shell: bash
12 changes: 12 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ jobs:
- name: Build
run: yarn workspace ${{ matrix.app }} build
shell: bash
- name: Download daemon binary
run: yarn workspace ${{ matrix.app }} download:binary
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Package executable bundles, sign and notarize, make distributables
env:
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
Expand All @@ -78,6 +83,11 @@ jobs:
- name: Build
run: yarn workspace ${{ matrix.app }} build
shell: bash
- name: Download daemon binary
run: yarn workspace ${{ matrix.app }} download:binary
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Package executable bundles, make distributables
run: yarn workspace ${{ matrix.app }} make --arch=arm64,x64
shell: bash
Expand All @@ -101,6 +111,8 @@ jobs:
- name: Download daemon binary
run: yarn workspace ${{ matrix.app }} download:binary
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Package executable bundles, sign and notarize, make distributables
run: |
yarn workspace ${{ matrix.app }} make --arch=x64
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
- name: Download daemon binary
run: yarn workspace ${{ matrix.app }} download:binary
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Package executable bundles, sign and notarize, make and publish distributables
env:
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
Expand Down Expand Up @@ -84,6 +86,8 @@ jobs:
- name: Download daemon binary
run: yarn workspace ${{ matrix.app }} download:binary
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Package executable bundles, make and publish distributables
env:
BUCKET_ACCESS_KEY_ID: ${{ secrets.BUCKET_ACCESS_KEY_ID }}
Expand Down Expand Up @@ -111,6 +115,8 @@ jobs:
- name: Download daemon binary
run: yarn workspace ${{ matrix.app }} download:binary
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Package executable bundles, sign and notarize, make and publish distributables
env:
BUCKET_ACCESS_KEY_ID: ${{ secrets.BUCKET_ACCESS_KEY_ID }}
Expand Down
1 change: 1 addition & 0 deletions hostd/forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
appleApiKeyId: process.env.APPLE_API_KEY,
appleApiIssuer: process.env.APPLE_API_ISSUER,
},
extraResource: ['bin'],
icon: './assets/icons/icon',
},
rebuildConfig: {},
Expand Down
17 changes: 13 additions & 4 deletions hostd/main/asset.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import path from 'path'
import { env } from './env'

export function getResourcePath(name: string) {
return path.join(process.resourcesPath, name)
}

export function getResourceAsarPath(name: string) {
return getResourcePath(path.join('app.asar', name))
}

export function getResourceAsarUnpackedPath(name: string) {
return getResourcePath(path.join('app.asar.unpacked', name))
}

export function getAsset(name: string) {
return env.isDev
? path.join(process.cwd(), 'assets', name)
: path.join(__dirname, '../assets', name)
return getResourceAsarPath(path.join('assets', name))
}
6 changes: 2 additions & 4 deletions hostd/main/binary.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as path from 'path'
import { env } from './env'
import { getResourcePath } from './asset'

export function getBinaryDirectoryPath(): string {
return env.isDev
? path.join(process.cwd(), 'bin')
: path.join(__dirname, '../bin')
return getResourcePath('bin')
}

export function getBinaryFilePath(): string {
Expand Down
6 changes: 3 additions & 3 deletions hostd/main/window.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path, { join } from 'path'
import { join } from 'path'
import { BrowserWindow, app } from 'electron'
import { format } from 'url'
import { state } from './state'
import { system } from './system'
import { getAsset } from './asset'
import { getAsset, getResourceAsarPath } from './asset'
import { env } from './env'

export function initWindow() {
Expand All @@ -30,7 +30,7 @@ export function initWindow() {
const url = env.isDev
? 'http://localhost:8000/'
: format({
pathname: path.join(__dirname, '../../renderer/out/index.html'),
pathname: getResourceAsarPath('renderer/out/index.html'),
protocol: 'file:',
slashes: true,
})
Expand Down
9 changes: 0 additions & 9 deletions hostd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,5 @@
"postcss": "^8.4.31",
"rimraf": "^3.0.2",
"typescript": "5.0.3"
},
"build": {
"icon": "assets/appicon.png",
"asar": true,
"files": [
"dist",
"assets",
"bin"
]
}
}
6 changes: 4 additions & 2 deletions hostd/scripts/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ downloadRelease()

async function downloadRelease(): Promise<void> {
try {
const octokit = new Octokit()
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
})
const releaseData = await octokit.repos.getLatestRelease({
owner: 'SiaFoundation',
repo: 'hostd',
Expand Down Expand Up @@ -138,7 +140,7 @@ function releaseAsset(): string {
}
}

return `renterd_${goos}_${goarch}.zip`
return `hostd_${goos}_${goarch}.zip`
}

function getBinaryDirectoryPath(): string {
Expand Down
1 change: 1 addition & 0 deletions renterd/forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
appleApiKeyId: process.env.APPLE_API_KEY,
appleApiIssuer: process.env.APPLE_API_ISSUER,
},
extraResource: ['bin'],
icon: './assets/icons/icon',
},
rebuildConfig: {},
Expand Down
17 changes: 13 additions & 4 deletions renterd/main/asset.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import path from 'path'
import { env } from './env'

export function getResourcePath(name: string) {
return path.join(process.resourcesPath, name)
}

export function getResourceAsarPath(name: string) {
return getResourcePath(path.join('app.asar', name))
}

export function getResourceAsarUnpackedPath(name: string) {
return getResourcePath(path.join('app.asar.unpacked', name))
}

export function getAsset(name: string) {
return env.isDev
? path.join(process.cwd(), 'assets', name)
: path.join(__dirname, '../assets', name)
return getResourceAsarPath(path.join('assets', name))
}
6 changes: 2 additions & 4 deletions renterd/main/binary.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as path from 'path'
import { env } from './env'
import { getResourcePath } from './asset'

export function getBinaryDirectoryPath(): string {
return env.isDev
? path.join(process.cwd(), 'bin')
: path.join(__dirname, '../bin')
return getResourcePath('bin')
}

export function getBinaryFilePath(): string {
Expand Down
1 change: 1 addition & 0 deletions renterd/main/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function startDaemon(): Promise<void> {
await stopDaemon()
const config = getConfig()
const binaryFilePath = getBinaryFilePath()

state.daemon = spawn(binaryFilePath, [], {
env: { ...process.env, RENTERD_CONFIG_FILE: getConfigFilePath() },
cwd: config.directory,
Expand Down
6 changes: 3 additions & 3 deletions renterd/main/window.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path, { join } from 'path'
import { join } from 'path'
import { BrowserWindow, app } from 'electron'
import { format } from 'url'
import { state } from './state'
import { system } from './system'
import { getAsset } from './asset'
import { getAsset, getResourceAsarPath } from './asset'
import { env } from './env'

export function initWindow() {
Expand All @@ -30,7 +30,7 @@ export function initWindow() {
const url = env.isDev
? 'http://localhost:8000/'
: format({
pathname: path.join(__dirname, '../../renderer/out/index.html'),
pathname: getResourceAsarPath('renderer/out/index.html'),
protocol: 'file:',
slashes: true,
})
Expand Down
9 changes: 0 additions & 9 deletions renterd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,5 @@
"postcss": "^8.4.31",
"rimraf": "^3.0.2",
"typescript": "5.0.3"
},
"build": {
"icon": "assets/appicon.png",
"asar": true,
"files": [
"dist",
"assets",
"bin"
]
}
}
4 changes: 3 additions & 1 deletion renterd/scripts/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ downloadRelease()

async function downloadRelease(): Promise<void> {
try {
const octokit = new Octokit()
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
})
const releaseData = await octokit.repos.getLatestRelease({
owner: 'SiaFoundation',
repo: 'renterd',
Expand Down

0 comments on commit 4c54e8d

Please sign in to comment.