Skip to content

Commit ada7581

Browse files
committed
Adding supprot for go installs
1 parent bfcb363 commit ada7581

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

examples/nginx-alpine.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: "1.0"
2+
services:
3+
nginx:
4+
image: alpine:3.19
5+
security:
6+
isolation: strict
7+
apparmor_profile: lxc-container-default-restricted
8+
capabilities:
9+
- NET_BIND_SERVICE # Required for nginx to bind to port 80
10+
cpu:
11+
cores: 1
12+
shares: 512
13+
memory:
14+
limit: 256M
15+
swap: 128M
16+
network:
17+
type: bridge
18+
bridge: vmbr0
19+
ip: dhcp # Using DHCP for automatic IP assignment
20+
ports:
21+
- "80:80" # Expose nginx HTTP port
22+
storage:
23+
root: 2G # Alpine is very small, 2G is plenty
24+
environment:
25+
TZ: UTC
26+
command: ["/bin/sh", "-c", "apk add --no-cache nginx && nginx -g 'daemon off;'"] # Install and run nginx
27+
# Alternatively, you could use a startup script:
28+
# command: ["/bin/sh", "-c", "apk add --no-cache nginx && mkdir -p /run/nginx && nginx -g 'daemon off;'"]

internal/cli/root.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/larkinwc/proxmox-lxc-compose/pkg/logging"
8+
"github.com/spf13/cobra"
9+
"github.com/spf13/viper"
10+
)
11+
12+
var (
13+
cfgFile string
14+
debugMode bool
15+
development bool
16+
rootCmd *cobra.Command
17+
)
18+
19+
func init() {
20+
cobra.OnInitialize(initConfig)
21+
rootCmd = &cobra.Command{
22+
Use: "lxc-compose",
23+
Short: "A docker-compose like tool for managing LXC containers in Proxmox",
24+
}
25+
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.lxc-compose.yaml)")
26+
rootCmd.PersistentFlags().BoolVar(&debugMode, "debug", false, "enable debug mode")
27+
rootCmd.PersistentFlags().BoolVar(&development, "dev", false, "enable development mode")
28+
}
29+
30+
func initConfig() {
31+
if cfgFile != "" {
32+
viper.SetConfigFile(cfgFile)
33+
} else {
34+
home, err := os.UserHomeDir()
35+
cobra.CheckErr(err)
36+
viper.AddConfigPath(home)
37+
viper.SetConfigType("yaml")
38+
viper.SetConfigName(".lxc-compose")
39+
}
40+
41+
viper.AutomaticEnv()
42+
43+
if err := viper.ReadInConfig(); err == nil {
44+
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
45+
}
46+
47+
if debugMode {
48+
if err := logging.Init(logging.Config{
49+
Level: "debug",
50+
Development: true,
51+
}); err != nil {
52+
fmt.Fprintf(os.Stderr, "Failed to initialize logger: %v\n", err)
53+
}
54+
}
55+
56+
if development {
57+
if err := logging.Init(logging.Config{
58+
Level: "debug",
59+
Development: true,
60+
}); err != nil {
61+
fmt.Fprintf(os.Stderr, "Failed to initialize logger: %v\n", err)
62+
}
63+
}
64+
}
65+
66+
// Execute executes the root command
67+
func Execute() error {
68+
return rootCmd.Execute()
69+
}
70+
71+
// GetRootCmd returns the root command for adding subcommands
72+
func GetRootCmd() *cobra.Command {
73+
return rootCmd
74+
}

main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"log"
5+
6+
"github.com/larkinwc/proxmox-lxc-compose/internal/cli"
7+
)
8+
9+
func main() {
10+
if err := cli.Execute(); err != nil {
11+
log.Fatal(err)
12+
}
13+
}

0 commit comments

Comments
 (0)