commands

package
v0.0.0-...-758316b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Copyright © 2024 Adam Presley

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	PostgresVersion string = "15.2"
)

Variables

View Source
var CleanupApplicationCommand = sshutils.Step{
	Commands: []sshutils.Command{
		sshutils.NewCommand(
			`cd applications/{{.ServiceName}} && rm ./{{.ServiceName}}-latest.tar`,
			"Cleaning up after application setup...",
		),
	},
	StartingMessage: "Cleaning...",
	SuccessMessage:  "Dirt cleaned up.",
	ErrorMessage:    "There was a problem cleaning: %s",
}
View Source
var LoadDockerApplicationCommand = sshutils.Step{
	Commands: []sshutils.Command{
		sshutils.NewCommand(
			`cd ~/applications/{{.ServiceName}} && docker load -i {{.ServiceName}}-latest.tar`,
			"Loading application...",
		),
	},
	StartingMessage: "Loading your application...",
	SuccessMessage:  "Application loaded successfully.",
	ErrorMessage:    "There was a problem loading your application: %s",
}
View Source
var SetupApplicationCommand = sshutils.Step{
	Commands: []sshutils.Command{
		sshutils.NewCommand(
			`cd ~ && mkdir -p applications/{{.ServiceName}}`,
			"Preparing {{.ServiceName}}...",
		),
		sshutils.NewCommand(
			`cd ~/applications/{{.ServiceName}} && tee docker-compose.yml <<EOF
services:
  {{.ServiceName}}:
    image: {{.ServiceName}}:latest
    container_name: {{.ServiceName}}
    restart: unless-stopped
    ports:
      - 127.0.0.1:{{.Port}}:{{.Port}}
    env_file:
      - {{.EnvFile}}{{if len .Dependencies}}
    depends_on:{{range .Dependencies}}
      - {{.}}{{end}}{{end}}{{if len .Mounts}}
    volumes:{{range .Mounts}}
      - {{.}}{{end}}{{end}}
    networks:
      - applications
    labels:
      - traefik.enable=true
      - traefik.http.routers.{{.ServiceName}}.rule=Host("{{.Domain}}")
      - traefik.http.services.{{.ServiceName}}.loadbalancer.server.port={{.Port}}
      - traefik.http.routers.{{.ServiceName}}.tls=true
      - traefik.http.routers.{{.ServiceName}}.tls.certresolver=default
      - traefik.docker.network=applications

networks:
  applications:
    external: true
EOF`,
			"Preparing {{.ServiceName}}...",
		),
	},
	StartingMessage: "Setting up your application...",
	SuccessMessage:  "Application setup successfully.",
	ErrorMessage:    "There was a problem setting up your application: %s",
}
View Source
var SetupBaseServerCommand = sshutils.Step{
	Commands: []sshutils.Command{
		sshutils.NewCommand(
			"sudo apt update -y",
			"Updating packages list...",
		),
		sshutils.NewCommand(
			"sudo apt upgrade -y",
			"Upgrading OS packages...",
		),
		sshutils.NewCommand(
			"sudo apt install ca-certificates curl wget htop neovim git -y",
			"Installing additional packages...",
		),
		sshutils.NewCommand(
			"cd ~ && mkdir -p /applications/ && mkdir -p /services/",
			"Setting up directories...",
		),
	},
	StartingMessage: "Updating OS and installing base software components...",
	SuccessMessage:  "Server update and software installed successfully.",
	ErrorMessage:    "There was a problem updating the OS and installing software components: %s",
}
View Source
var SetupDockerCommand = sshutils.Step{
	Commands: []sshutils.Command{
		sshutils.NewCommand(
			"sudo install -m 0755 -d /etc/apt/keyrings",
			"Setting up keyring...",
		),
		sshutils.NewCommand(
			"sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc",
			"Setting up keyring...",
		),
		sshutils.NewCommand(
			"sudo chmod a+r /etc/apt/keyrings/docker.asc",
			"Setting up keyring...",
		),
		sshutils.NewCommand(
			`echo \
         "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
         $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
         sudo tee /etc/apt/sources.list.d/docker.list > /dev/null`,
			"Setting up keyring...",
		),
		sshutils.NewCommand(
			"sudo apt update -y",
			"Updating package list...",
		),
		sshutils.NewCommand(
			"sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y",
			"Installing Docker...",
		),
		sshutils.NewCommand(
			"sudo usermod -aG docker {{.User}}",
			"Adding user to 'docker' group...",
		),
		sshutils.NewCommand(
			`sudo docker network create -d bridge applications || true && sudo docker network create -d bridge web || true`,
			"Setting up Docker network...",
		),
		sshutils.NewCommand(
			`cd ~ && wget https://github.com/jesseduffield/lazydocker/releases/download/v`+lazyDockerVersion+`/lazydocker_`+lazyDockerVersion+`_Linux_x86_64.tar.gz`,
			"Installing LazyDocker...",
		),
		sshutils.NewCommand(
			`cd ~ && mkdir -p ./lazydocker && tar xvf ./lazydocker_`+lazyDockerVersion+`_Linux_x86_64.tar.gz -C ./lazydocker && sudo ln -sf ~/lazydocker/lazydocker /usr/local/bin/lazydocker`,
			"Installing LazyDocker...",
		),
		sshutils.NewCommand(
			`rm ./lazydocker_`+lazyDockerVersion+`_Linux_x86_64.tar.gz`,
			"Cleaning up...",
		),
	},
	StartingMessage: "Setting up Docker...",
	SuccessMessage:  "Docker setup successfully.",
	ErrorMessage:    "There was a problem setting up Docker: %s",
}
View Source
var SetupServicePostgresCommand = sshutils.Step{
	Commands: []sshutils.Command{
		sshutils.NewCommand(
			`cd ~ && mkdir -p services/postgres/data`,
			"Installing PostgreSQL...",
		),
		sshutils.NewCommand(
			`cd ~/services/postgres && tee docker-compose.yml <<EOF
services:
  postgres:
    image: postgres:`+PostgresVersion+`
    container_name: postgres
    restart: unless-stopped
    ports:
      - 127.0.0.1:5432:5432
    environment:{{range $key, $value := .Env}}
      {{$key}}: "{{$value}}"{{end}}
    volumes:
      - ~/services/postgres/data:/var/lib/postgresql/data
    networks:
      - applications

networks:
  applications:
    external: true
EOF`,
			"Installing PostgreSQL...",
		),
		sshutils.NewCommand(
			`cd services/postgres && sudo docker compose up -d`,
			"Starting PostgreSQL...",
		),
	},
	StartingMessage: "Setting up PostgreSQL...",
	SuccessMessage:  "PostgreSQL setup successfully.",
	ErrorMessage:    "There was a problem setting up PostgreSQL: %s",
}
View Source
var SetupTraefikCommand = sshutils.Step{
	Commands: []sshutils.Command{
		sshutils.NewCommand(
			`cd ~ && mkdir -p traefik/ssl-certs`,
			"Installing Traefik...",
		),
		sshutils.NewCommand(
			`cd ~/traefik && tee docker-compose.yml <<EOF
services:
  traefik:
    image: traefik:v3.1
    container_name: traefik
    command: --api-insecure=false --providers.docker
    restart: unless-stopped
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ~/traefik/traefik.yml:/etc/traefik/traefik.yml
      - ~/traefik/ssl-certs:/ssl-certs/
    networks:
      - web
      - applications

networks:
  web:
    external: true
  applications:
    external: true
EOF`,
			"Installing Traefik...",
		),
		sshutils.NewCommand(
			`cd ~/traefik && tee traefik.yml <<EOF
global:
  checkNewVersion: true
  sendAnonymousUsage: false

api:
  dashboard: false
  # Set insecure to false for production!
  insecure: false

entryPoints:
  web:
    address: :80
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https

  websecure:
    address: :443
    http:
      tls:
        certResolver: default

certificatesResolvers:
  default:
    acme:
      email: {{.Email}}
      storage: /ssl-certs/acme.json
      httpChallenge:
        entryPoint: web

providers:
  docker:
    exposedByDefault: false
EOF`,
			"Installing Traefik...",
		),
		sshutils.NewCommand(
			`cd traefik && sudo docker compose up -d`,
			"Starting Traefik...",
		),
	},
	StartingMessage: "Setting up Traefik...",
	SuccessMessage:  "Traefik setup successfully.",
	ErrorMessage:    "There was a problem setting up Traefik: %s",
}
View Source
var StartApplicationCommand = sshutils.Step{
	Commands: []sshutils.Command{
		sshutils.NewCommand(
			`cd applications/{{.ServiceName}} && sudo docker compose up -d`,
			"Starting application...",
		),
	},
	StartingMessage: "Starting your application...",
	SuccessMessage:  "Application started successfully.",
	ErrorMessage:    "There was a problem starting your application: %s",
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL