Skip to content

Commit

Permalink
fix pipe closed issue, and a lot of other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
juls0730 committed Dec 14, 2024
1 parent 7689999 commit de22bd2
Show file tree
Hide file tree
Showing 23 changed files with 1,031 additions and 794 deletions.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.23-bookworm as builder

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN GOOS=linux go build -o fluxd cmd/fluxd/main.go

RUN (curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.36.0/pack-v0.36.0-linux.tgz" | tar -C /usr/local/bin/ --no-same-owner -xzv pack)
RUN apt-get install -y ca-certificates

EXPOSE 5647 7465

VOLUME [ "/var/run/docker.sock" ]

CMD ["/app/fluxd"]
53 changes: 49 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,62 @@ Flux is a lightweight self-hosted pseudo-PaaS for hosting Golang web apps with e

To install and start the Flux daemon using ZQDGR, run the following command:

> [!IMPORTANT]
> CGO is required to build the daemon due to the use of [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3)
#### Method 1: ZQDGR

```bash
# method 1
go install github.com/juls0730/zqdgr@latest

git clone https://github.com/juls0730/flux.git
cd flux

# either
zqdgr build:daemon
sudo ./fluxd

# method 2
# or
FLUXD_ROOT_DIR=$PWD/fluxdd zqdgr run:daemon
```

> [!IMPORTANT]
> CGO is required to build the daemon due to the use of [mattn/go-sqlite3](https://github.com/mattn/go-sqlite3)
#### Method 2: Docker

```bash
docker run -d --name fluxd --network host -v /var/run/docker.sock:/var/run/docker.sock -v fluxd-data:/var/fluxd -p 5647:5647 -p 7465:7465 zoeissleeping/fluxd:latest
```

#### Method 3: Systemd

```bash
go install github.com/juls0730/zqdgr@latest

git clone https://github.com/juls0730/flux.git
cd flux

zqdgr build:daemon
sudo mv fluxd /usr/local/bin/

sudo cat <<EOF > /etc/systemd/system/fluxd.service
[Unit]
Description=Flux Daemon
After=network.target
[Service]
ExecStart=/usr/local/bin/fluxd
WorkingDirectory=/var/fluxd
User=fluxuser
Group=fluxgroup
Restart=always
Environment=FLUXD_ROOT_DIR=/var/fluxd
[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now fluxd
```

### CLI

Expand Down
113 changes: 113 additions & 0 deletions cmd/flux/handlers/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package handlers

import (
"fmt"
"io"
"net/http"
"strings"

"github.com/briandowns/spinner"
"github.com/juls0730/flux/cmd/flux/models"
"github.com/juls0730/flux/pkg"
)

func DeleteCommand(seekingHelp bool, config models.Config, info pkg.Info, loadingSpinner *spinner.Spinner, spinnerWriter *models.CustomSpinnerWriter, args []string) error {
if seekingHelp {
fmt.Println(`Usage:
flux delete [project-name | all]
Options:
project-name: The name of the project to delete
all: Delete all projects
Flux will delete the deployment of the app in the current directory or the specified project.`)
return nil
}

if len(args) == 1 {
if args[0] == "all" {
var response string
fmt.Print("Are you sure you want to delete all projects? this will delete all volumes and containers associated and cannot be undone. \n[y/N] ")
fmt.Scanln(&response)

if strings.ToLower(response) != "y" {
fmt.Println("Aborting...")
return nil
}

response = ""

fmt.Printf("Are you really sure you want to delete all projects? \n[y/N] ")
fmt.Scanln(&response)

if strings.ToLower(response) != "y" {
fmt.Println("Aborting...")
return nil
}

req, err := http.NewRequest("DELETE", config.DeamonURL+"/deployments", nil)
if err != nil {
return fmt.Errorf("failed to delete deployments: %v", err)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("failed to delete deployments: %v", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("error reading response body: %v", err)
}

responseBody = []byte(strings.TrimSuffix(string(responseBody), "\n"))

return fmt.Errorf("delete failed: %s", responseBody)
}

fmt.Printf("Successfully deleted all projects\n")
return nil
}
}

projectName, err := GetProjectName("delete", args)
if err != nil {
return err
}

// ask for confirmation
fmt.Printf("Are you sure you want to delete %s? this will delete all volumes and containers associated with the deployment, and cannot be undone. \n[y/N] ", projectName)
var response string
fmt.Scanln(&response)

if strings.ToLower(response) != "y" {
fmt.Println("Aborting...")
return nil
}

req, err := http.NewRequest("DELETE", config.DeamonURL+"/deployments/"+projectName, nil)
if err != nil {
return fmt.Errorf("failed to delete app: %v", err)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("failed to delete app: %v", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("error reading response body: %v", err)
}

responseBody = []byte(strings.TrimSuffix(string(responseBody), "\n"))

return fmt.Errorf("delete failed: %s", responseBody)
}

fmt.Printf("Successfully deleted %s\n", projectName)

return nil
}
Loading

0 comments on commit de22bd2

Please sign in to comment.