Working with deployment to fly.io
This commit is contained in:
parent
7bcdd2dd80
commit
26c47a0e8c
8 changed files with 115 additions and 9 deletions
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/AYM1607/ccclip/internal/configfile"
|
||||
"github.com/spf13/cobra"
|
||||
|
|
@ -34,7 +35,8 @@ var getClipboardCmd = &cobra.Command{
|
|||
return fmt.Errorf("could not set clipboard: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Your current clipbard is %q\n", plain)
|
||||
fmt.Printf("Your current clipbard is:")
|
||||
fmt.Fprintf(os.Stdout, plain)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ func b64(i []byte) string {
|
|||
var apiclient *client.Client
|
||||
|
||||
func init() {
|
||||
apiclient = client.New("http://localhost:8080")
|
||||
apiclient = client.New("https://api.ccclip.io")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
19
cmd/server/Dockerfile
Normal file
19
cmd/server/Dockerfile
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
FROM golang:1.21-alpine AS builder
|
||||
# Ensure we have a c compiler.
|
||||
RUN apk add --no-cache build-base ca-certificates fuse3 sqlite
|
||||
|
||||
# Install LiteFS for distribute SQLite
|
||||
COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs
|
||||
|
||||
COPY cmd/server/litefs.yml /etc/litefs.yml
|
||||
|
||||
WORKDIR /src
|
||||
COPY go.mod .
|
||||
COPY go.sum .
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN go build -ldflags='-s -w' -tags 'linux' -trimpath -o /dist/app ./cmd/server
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENTRYPOINT ["litefs", "mount"]
|
||||
46
cmd/server/litefs.yml
Normal file
46
cmd/server/litefs.yml
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# The fuse section describes settings for the FUSE file system. This file system
|
||||
# is used as a thin layer between the SQLite client in your application and the
|
||||
# storage on disk. It intercepts disk writes to determine transaction boundaries
|
||||
# so that those transactions can be saved and shipped to replicas.
|
||||
fuse:
|
||||
dir: "/litefs"
|
||||
|
||||
# The data section describes settings for the internal LiteFS storage. We'll
|
||||
# mount a volume to the data directory so it can be persisted across restarts.
|
||||
# However, this data should not be accessed directly by the user application.
|
||||
data:
|
||||
dir: "/var/lib/litefs"
|
||||
|
||||
# This flag ensure that LiteFS continues to run if there is an issue on starup.
|
||||
# It makes it easy to ssh in and debug any issues you might be having rather
|
||||
# than continually restarting on initialization failure.
|
||||
exit-on-error: false
|
||||
|
||||
# This section defines settings for the option HTTP proxy.
|
||||
# This proxy can handle primary forwarding & replica consistency
|
||||
# for applications that use a single SQLite database.
|
||||
proxy:
|
||||
addr: ":8080"
|
||||
target: "localhost:3000"
|
||||
db: "ccclip.db"
|
||||
|
||||
# This section defines a list of commands to run after LiteFS has connected
|
||||
# and sync'd with the cluster. You can run multiple commands but LiteFS expects
|
||||
# the last command to be long-running (e.g. an application server). When the
|
||||
# last command exits, LiteFS is shut down.
|
||||
exec:
|
||||
- cmd: "/dist/app"
|
||||
|
||||
# The lease section specifies how the cluster will be managed. We're using the
|
||||
# "consul" lease type so that our application can dynamically change the primary.
|
||||
#
|
||||
# These environment variables will be available in your Fly.io application.
|
||||
lease:
|
||||
type: "consul"
|
||||
advertise-url: "http://${HOSTNAME}.vm.${FLY_APP_NAME}.internal:20202"
|
||||
candidate: ${FLY_REGION == PRIMARY_REGION}
|
||||
promote: true
|
||||
|
||||
consul:
|
||||
url: "${FLY_CONSUL_URL}"
|
||||
key: "litefs/${FLY_APP_NAME}"
|
||||
27
fly.toml
Normal file
27
fly.toml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# fly.toml app configuration file generated for dark-paper-8180 on 2023-11-10T08:23:22Z
|
||||
#
|
||||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
||||
#
|
||||
|
||||
app = "dark-paper-8180"
|
||||
primary_region = "sea"
|
||||
|
||||
[build]
|
||||
dockerfile = "./cmd/server/Dockerfile"
|
||||
|
||||
[env]
|
||||
CCCLIP_LOAD_RAW_KEYS = "true"
|
||||
CCCLIP_PORT = "3000"
|
||||
CCCLIP_DATABASE_LOCATION = "/litefs/ccclip.db"
|
||||
|
||||
[mounts]
|
||||
source = "litefs"
|
||||
destination = "/var/lib/litefs"
|
||||
|
||||
[http_service]
|
||||
internal_port = 8080
|
||||
# force_https = true
|
||||
auto_stop_machines = true
|
||||
auto_start_machines = true
|
||||
min_machines_running = 1
|
||||
processes = ["app"]
|
||||
3
go.mod
3
go.mod
|
|
@ -4,16 +4,15 @@ go 1.21
|
|||
|
||||
require (
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/mattn/go-sqlite3 v1.14.18
|
||||
github.com/oklog/ulid/v2 v2.1.0
|
||||
github.com/spf13/cobra v1.8.0
|
||||
golang.org/x/crypto v0.14.0
|
||||
golang.org/x/term v0.13.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.18 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
)
|
||||
|
|
|
|||
3
go.sum
3
go.sum
|
|
@ -19,8 +19,5 @@ golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
|||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
|
||||
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
|||
|
|
@ -81,18 +81,34 @@ func PublicKeyFromBytes(keyBytes []byte) *ecdh.PublicKey {
|
|||
}
|
||||
|
||||
func LoadPrivateKey(fp string) (*ecdh.PrivateKey, error) {
|
||||
kb, err := loadKey(fp)
|
||||
var kb []byte
|
||||
var err error
|
||||
if os.Getenv("CCCLIP_LOAD_RAW_KEYS") == "" {
|
||||
kb, err = loadKey(fp)
|
||||
} else {
|
||||
kb = make([]byte, KeySize)
|
||||
base64.StdEncoding.Decode(kb, []byte(fp))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return PrivateKeyFromBytes(kb), nil
|
||||
}
|
||||
|
||||
func LoadPublicKey(fp string) (*ecdh.PublicKey, error) {
|
||||
kb, err := loadKey(fp)
|
||||
var kb []byte
|
||||
var err error
|
||||
if os.Getenv("CCCLIP_LOAD_RAW_KEYS") == "" {
|
||||
kb, err = loadKey(fp)
|
||||
} else {
|
||||
kb = make([]byte, KeySize)
|
||||
base64.StdEncoding.Decode(kb, []byte(fp))
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return PublicKeyFromBytes(kb), nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue