Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/go .
{
"name": "Go",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/go:2-1.25-trixie",

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/go:1": {},
"ghcr.io/guiyomh/features/golangci-lint:0": {},
"ghcr.io/guiyomh/features/goreleaser:0": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"openai.chatgpt",
"golang.Go"
],
"settings": {
// Slightly different dark theme to highlight the DevContainer
"workbench.colorTheme": "Default Dark Modern",
"workbench.colorCustomizations": {
"statusBar.background": "#005f73",
"statusBar.noFolderBackground": "#005f73",
"statusBar.debuggingBackground": "#9b2226",
"statusBar.foreground": "#ffffff"
}
}
}
},

// Preserve the packages configurations within the container on a host volume: git, codex-extension.
"mounts": [
"source=codex-session,target=/home/vscode/.codex,type=volume",
"source=gitconfig,target=/home/vscode/.gitconfig-volume,type=volume"
],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "./.devcontainer/setup.sh",

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "vscode"
}
29 changes: 29 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail

if ! command -v task >/dev/null; then
echo "Installing Taskfile CLI helper..." >&2
curl -1sLf 'https://dl.cloudsmith.io/public/task/task/setup.deb.sh' | sudo -E bash
sudo apt install -y task
fi

sudo chown -R ${UID}:${UID} ${HOME}/.codex

# Fix project file permissions to standard privileges
sudo chown -R ${UID}:${UID} ${PWD}
sudo find ${PWD} -type d -exec chmod 755 {} +
sudo find ${PWD} -type f ! -name "*.sh" -exec chmod 644 {} +
sudo find ${PWD} -type f -name "*.sh" -exec chmod 755 {} +

# Setup git files configurations
sudo chown -R ${UID}:${UID} ${HOME}/.gitconfig-volume

touch ${HOME}/.gitconfig-volume/config
ln -fs ${HOME}/.gitconfig-volume/config ${HOME}/.gitconfig
sudo chown -R ${UID}:${UID} ${HOME}/.gitconfig

touch ${HOME}/.gitconfig-volume/.git-credentials
ln -fs ${HOME}/.gitconfig-volume/.git-credentials ${HOME}/.git-credentials
sudo chown -R ${UID}:${UID} ${HOME}/.git-credentials

git config --global --add safe.directory ${PWD}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
hapi
hapi
bin/
dist/
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ hapi vps vm list

See the [full reference documentation](https://github.com/hostinger/api-cli/blob/main/docs/hapi.md) for information about each available command.

# Building from source

If you need to compile `hapi` yourself, the repository ships with a `Taskfile.yml` that automates downloading dependencies, cross-building every supported platform and packaging the binaries.

Inside the repository, install [`Task CLI`](https://taskfile.dev) or use the [devcontainer](https://containers.dev) terminal, then run:

```bash
task clean # remove previous artifacts
task release # builds linux/darwin/windows binaries
```

Each tarball is created under `dist/` with the pattern `hapi-<tag>-<os>-<arch>.tar.gz`, and the native host binary lands at `dist/host/<os>-<arch>/hapi`.

You can also build a single target manually if you prefer:
```bash
# a binary for your device
go build -ldflags="-s -w" -o hapi main.go
```

```bash
# or for specific arch
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o hapi main.go
```

Finally, copy the resulting binary into your `$PATH` or package it for the target device.

# Enabling shell auto-completion (optional)

`hapi` has auto-complete support. This makes it easier to use the CLI and improves user experience by completing command
Expand All @@ -59,4 +85,4 @@ Auto-completion can be generated for multiple shells. The currently supported sh

After adding shell auto-completion, remember to refresh your shell profile by logging out from the shell and log back in.

Read more on [how to enable auto-completion](https://github.com/hostinger/api-cli/blob/main/AUTOCOMPLETE.md).
Read more on [how to enable auto-completion](https://github.com/hostinger/api-cli/blob/main/AUTOCOMPLETE.md).
157 changes: 157 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
version: '3'

env:
DIST_DIR: dist
BINARY: hapi
LDFLAGS: -s -w

tasks:
default:
desc: List the available tasks without executing any of them.
silent: true
cmds:
- task --list

clean:
desc: Remove previously generated artifacts.
cmds:
- rm -rf ${DIST_DIR}

ensure:
desc: Download Go modules before building.
cmds:
- go mod download

build:
desc: Build the CLI for the host platform.
deps: [ensure]
cmds:
- mkdir -p ${DIST_DIR}/host
- go build -ldflags="${LDFLAGS}" -o ${DIST_DIR}/host/${BINARY} main.go

build.linux-amd64:
desc: Build Linux amd64 binary.
deps: [ensure]
cmds:
- mkdir -p ${DIST_DIR}/linux-amd64
- GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o ${DIST_DIR}/linux-amd64/${BINARY} main.go

build.linux-arm64:
desc: Build Linux arm64 binary.
deps: [ensure]
cmds:
- mkdir -p ${DIST_DIR}/linux-arm64
- GOOS=linux GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o ${DIST_DIR}/linux-arm64/${BINARY} main.go

build.darwin-amd64:
desc: Build macOS amd64 binary.
deps: [ensure]
cmds:
- mkdir -p ${DIST_DIR}/darwin-amd64
- GOOS=darwin GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o ${DIST_DIR}/darwin-amd64/${BINARY} main.go

build.darwin-arm64:
desc: Build macOS arm64 binary.
deps: [ensure]
cmds:
- mkdir -p ${DIST_DIR}/darwin-arm64
- GOOS=darwin GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o ${DIST_DIR}/darwin-arm64/${BINARY} main.go

build.linux-386:
desc: Build Linux 386 binary.
deps: [ensure]
cmds:
- mkdir -p ${DIST_DIR}/linux-386
- GOOS=linux GOARCH=386 go build -ldflags="${LDFLAGS}" -o ${DIST_DIR}/linux-386/${BINARY} main.go

build.windows-386:
desc: Build Windows 386 binary.
deps: [ensure]
cmds:
- mkdir -p ${DIST_DIR}/windows-386
- GOOS=windows GOARCH=386 go build -ldflags="${LDFLAGS}" -o ${DIST_DIR}/windows-386/${BINARY}.exe main.go

build.windows-amd64:
desc: Build Windows amd64 binary.
deps: [ensure]
cmds:
- mkdir -p ${DIST_DIR}/windows-amd64
- GOOS=windows GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o ${DIST_DIR}/windows-amd64/${BINARY}.exe main.go

build.windows-arm64:
desc: Build Windows arm64 binary.
deps: [ensure]
cmds:
- mkdir -p ${DIST_DIR}/windows-arm64
- GOOS=windows GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o ${DIST_DIR}/windows-arm64/${BINARY}.exe main.go

package.linux-amd64:
desc: Package the Linux amd64 binary into a tarball.
deps: [build.linux-amd64]
cmds:
- sh -c 'version=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD); tar czf ${DIST_DIR}/${BINARY}-$version-linux-amd64.tar.gz -C ${DIST_DIR}/linux-amd64 ${BINARY}'

package.linux-arm64:
desc: Package the Linux arm64 binary into a tarball.
deps: [build.linux-arm64]
cmds:
- sh -c 'version=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD); tar czf ${DIST_DIR}/${BINARY}-$version-linux-arm64.tar.gz -C ${DIST_DIR}/linux-arm64 ${BINARY}'

package.darwin-arm64:
desc: Package the macOS arm64 binary into a tarball.
deps: [build.darwin-arm64]
cmds:
- sh -c 'version=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD); tar czf ${DIST_DIR}/${BINARY}-$version-darwin-arm64.tar.gz -C ${DIST_DIR}/darwin-arm64 ${BINARY}'

package.darwin-amd64:
desc: Package the macOS amd64 binary into a tarball.
deps: [build.darwin-amd64]
cmds:
- sh -c 'version=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD); tar czf ${DIST_DIR}/${BINARY}-$version-darwin-amd64.tar.gz -C ${DIST_DIR}/darwin-amd64 ${BINARY}'

package.linux-386:
desc: Package the Linux 386 binary into a tarball.
deps: [build.linux-386]
cmds:
- sh -c 'version=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD); tar czf ${DIST_DIR}/${BINARY}-$version-linux-386.tar.gz -C ${DIST_DIR}/linux-386 ${BINARY}'

package.windows-386:
desc: Package the Windows 386 binary into a tarball.
deps: [build.windows-386]
cmds:
- sh -c 'version=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD); tar czf ${DIST_DIR}/${BINARY}-$version-windows-386.tar.gz -C ${DIST_DIR}/windows-386 ${BINARY}.exe'

package.windows-amd64:
desc: Package the Windows amd64 binary into a tarball.
deps: [build.windows-amd64]
cmds:
- sh -c 'version=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD); tar czf ${DIST_DIR}/${BINARY}-$version-windows-amd64.tar.gz -C ${DIST_DIR}/windows-amd64 ${BINARY}.exe'

package.windows-arm64:
desc: Package the Windows arm64 binary into a tarball.
deps: [build.windows-arm64]
cmds:
- sh -c 'version=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD); tar czf ${DIST_DIR}/${BINARY}-$version-windows-arm64.tar.gz -C ${DIST_DIR}/windows-arm64 ${BINARY}.exe'

packages:
desc: Package every platform bundle.
deps:
- package.darwin-amd64
- package.darwin-arm64
- package.linux-386
- package.linux-amd64
- package.linux-arm64
- package.windows-386
- package.windows-amd64
- package.windows-arm64

package.checksums:
desc: Create SHA256 checksums for every release tarball.
deps: [packages]
cmds:
- sh -c 'version=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD); cd ${DIST_DIR}; sha256sum ${BINARY}-$version-*.tar.gz > ${BINARY}-$version-checksums.sha256'

release:
desc: Build and package every target used for releases.
deps:
- package.checksums