diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..e099ea4 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,70 @@ +name: Build and Release + +on: + push: + tags: + - 'v*.*.*' # Matches tags like v1.0.0, v2.1.3, etc. + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Check out the repository + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.16 + + - name: Run build script + run: ./build.sh + + - name: Upload build artifacts + uses: actions/upload-artifact@v3 + with: + name: build-artifacts + path: build/*.tar.gz + + release: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Download build artifacts + uses: actions/download-artifact@v3 + with: + name: build-artifacts + path: build + + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + + - name: Upload Release Assets for amd64 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: build/fly-linux-amd64.tar.gz + asset_name: fly-linux-amd64.tar.gz + asset_content_type: application/gzip + + - name: Upload Release Assets for arm64 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: build/fly-linux-arm64.tar.gz + asset_name: fly-linux-arm64.tar.gz + asset_content_type: application/gzip \ No newline at end of file diff --git a/README.md b/README.md index bf4c76e..c7c1225 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,96 @@ # server-cli -CLI tool for servers managed by FlyWP -## Commands +Easy CLI tool for servers managed by FlyWP. -### WP-CLI +## Installation -**wp-cli**: To access the `wp-cli`, you can use the following command from anywhere in the website folder, and the CLI will find the appropriate WordPress folder to execute the `wp` command. +### Prerequisites -```bash -fly wp -``` +- [Docker](https://www.docker.com/get-started) +- [Docker Compose](https://docs.docker.com/compose/install/) -**Any site**: +### Quick Install + +You can easily install the `fly` CLI tool using the following command. This will download and run the `install.sh` script, which will automatically detect your operating system and architecture, download the latest release, and install it to `/usr/local/bin`: ```bash -fly site wp +curl -sL https://raw.githubusercontent.com/flywp/server-cli/main/install.sh | bash ``` -In-case you want to run a `wp` command in a specific webwebsite, you could run like this. +### Manual Installation -### Site Operations +If you prefer to manually download and install the binary, follow these steps: + +1. Download the precompiled binaries from the [Releases](https://github.com/flywp/server-cli/releases) page. Choose the version suitable for your operating system and architecture. -Website names should *preferably* be autocompleted. +#### Linux + +1. Download the tarball: + ```bash + wget https://github.com/flywp/server-cli/releases/download/latest/fly-linux-amd64.tar.gz + ``` + +2. Extract the tarball: + ```bash + tar -xzf fly-linux-amd64.tar.gz + ``` + +3. Move the binary to a directory in your PATH: + ```bash + sudo mv fly-linux-amd64 /usr/local/bin/fly + ``` + +4. Verify the installation: + ```bash + fly --version + ``` + +## Usage + +### Base Docker Compose + +FlyWP has a base Docker Compose configuration for running MySQL, Redis, Ofelia, and Nginx Proxy that are shared for all sites hosted on the server. The base Docker Compose must be started before a site can be created. ```bash -fly site up -fly site down -fly site restart -fly site logs -fly site restart -fly site exec +fly base start # starts the base services (mysql, redis, nginx-proxy) +fly base stop # stops the base services +fly base restart # restarts the base services ``` -From anywhere inside a site folder: +### Site Operations + +From anywhere inside a site folder, you can run the following commands that will be executed on a per-site basis. ```bash -fly up -fly down -fly restart -fly logs -fly restart -fly exec +fly start # starts the website (via Docker Compose) +fly stop # stops the website (via Docker Compose) +fly restart # restarts the website (via Docker Compose) +fly wp # execute WP-CLI commands +fly logs # view logs from all containers or a single one +fly restart # restart a container +fly exec # execute commands inside a container. Default: "php" ``` -### Base Docker Compose +### WP-CLI + +**wp-cli**: To access `wp-cli`, use the following command from anywhere in the website folder. The CLI will find the appropriate WordPress folder to execute the `wp` command. ```bash -fly base stop -fly base start -fly base restart +fly wp ``` ### Global Commands +A few helper commands to debug the server installation and start/stop all sites. + ```bash -fly status -fly sites stop -fly sites start -fly sites restart +fly status # shows the status of the system +fly sites start # starts all sites +fly sites stop # stops all sites +fly sites restart # stops and starts all sites +``` + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. ``` diff --git a/build.sh b/build.sh index 19309e8..6a60336 100644 --- a/build.sh +++ b/build.sh @@ -19,6 +19,17 @@ build() { echo "Building for ${GOOS}/${GOARCH}..." GOOS=${GOOS} GOARCH=${GOARCH} go build -ldflags "${LDFLAGS}" -o "build/${OUTPUT}" . echo "Done building ${OUTPUT}" + + create_archive "${OUTPUT}" +} + +# Create tar.gz archive function +create_archive() { + local OUTPUT=$1 + + echo "Creating archive for ${OUTPUT}..." + tar -czvf "build/${OUTPUT}.tar.gz" -C build "${OUTPUT}" + echo "Done creating archive ${OUTPUT}.tar.gz" } # Clean build directory diff --git a/cmd/root.go b/cmd/root.go index e7c8893..d9aca14 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -37,5 +37,5 @@ func init() { // Cobra also supports local flags, which will only run // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + // rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..5390568 --- /dev/null +++ b/install.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +set -e + +# Determine OS and architecture +OS=$(uname -s | tr '[:upper:]' '[:lower:]') +ARCH=$(uname -m) + +if [ "$ARCH" == "x86_64" ]; then + ARCH="amd64" +elif [[ "$ARCH" == "armv7l" || "$ARCH" == "armv6l" ]]; then + ARCH="arm" +elif [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]]; then + ARCH="arm64" +else + echo "Unsupported architecture: $ARCH" + exit 1 +fi + +# Get latest release from GitHub API +LATEST_RELEASE=$(curl -s https://api.github.com/repos/flywp/server-cli/releases/latest) +TAG_NAME=$(echo "$LATEST_RELEASE" | grep -oP '"tag_name": "\K(.*)(?=")') +DOWNLOAD_URL=$(echo "$LATEST_RELEASE" | grep -oP '"browser_download_url": "\K(.*'${OS}'-'${ARCH}'.tar.gz)(?=")') + +if [ -z "$DOWNLOAD_URL" ]; then + echo "No suitable binary found for OS: $OS and architecture: $ARCH" + exit 1 +fi + +# Download the latest release +TEMP_DIR=$(mktemp -d) +DOWNLOAD_FILE="$TEMP_DIR/fly-$OS-$ARCH.tar.gz" + +echo "Downloading $DOWNLOAD_URL..." +curl -L -o "$DOWNLOAD_FILE" "$DOWNLOAD_URL" + +# Extract and install +echo "Extracting $DOWNLOAD_FILE..." +tar -xzf "$DOWNLOAD_FILE" -C "$TEMP_DIR" + +echo "Installing to /usr/local/bin/fly..." +sudo mv "$TEMP_DIR/fly-$OS-$ARCH" /usr/local/bin/fly +sudo chmod +x /usr/local/bin/fly + +# Clean up +rm -rf "$TEMP_DIR" + +echo "Installation completed! Verify with 'fly version'."