Skip to content

Commit

Permalink
feat(app): added ghcr.io mirror for images
Browse files Browse the repository at this point in the history
  • Loading branch information
varrcan committed May 2, 2022
1 parent fe5636d commit 6076446
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 10 deletions.
2 changes: 1 addition & 1 deletion command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ var configCmd = &cobra.Command{
Use: "config",
Short: "Application configuration",
Long: `Menu for setting up the application.`,
Hidden: true,
Hidden: false,
}
63 changes: 63 additions & 0 deletions command/config_repo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package command

import (
"fmt"
"log"

"github.com/dixonwille/wmenu/v5"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func init() {
configCmd.AddCommand(configRepoCmd)
}

var configRepoCmd = &cobra.Command{
Use: "repo",
Short: "Repository source configuration",
Long: `Menu for setting up the images source repository.`,
Run: func(cmd *cobra.Command, args []string) {
setRepo()
},
Hidden: false,
}

func setRepo() {
menu := wmenu.NewMenu("Select application repository source:")
menu.LoopOnInvalid()

menu.Action(func(opts []wmenu.Opt) error { fmt.Println(opts[0].Value); return nil })

locale := viper.GetString("repo")

menu.Option("ghcr.io", "ghcr.io", locale == "ghcr.io", func(opt wmenu.Opt) error {
saveRepoConfig(opt.Value)
return nil
})

menu.Option("quay.io", "quay.io", locale == "quay.io", func(opt wmenu.Opt) error {
saveRepoConfig(opt.Value)
return nil
})

err := menu.Run()
if err != nil {
log.Fatal(err)
}
}

func saveRepoConfig(lang interface{}) {
viper.Set("repo", lang)
err := viper.WriteConfig()
if err != nil {
log.Fatal(err)
}

switch lang {
case "ghcr.io":
fmt.Println("Selected ghcr.io")
case "quay.io":
fmt.Println("Selected quay.io")
}
}
6 changes: 6 additions & 0 deletions command/self_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func selfUpdate() {
spinnerTmp.Success()

viper.Set("version", *release.TagName)

repo := viper.GetString("repo")
if len(repo) == 0 {
viper.Set("repo", "ghcr.io")
}

err = viper.WriteConfig()
if err != nil {
pterm.FgRed.Println(err)
Expand Down
2 changes: 1 addition & 1 deletion config-files/docker-compose-apache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3.8"
services:
php:
container_name: ${HOST_NAME}_php
image: quay.io/local-deploy/php${PHP_VERSION:-7.3-apache}:${PHP_IMAGE_VERSION:-latest}
image: ${REPO}/local-deploy/php${PHP_VERSION:-7.4-apache}:${PHP_IMAGE_VERSION:-latest}
environment:
- "DOCUMENT_ROOT=${DOCUMENT_ROOT:-/var/www/html}"
- "HOST_NAME=${HOST_NAME:-localhost}"
Expand Down
2 changes: 1 addition & 1 deletion config-files/docker-compose-fpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3.8"
services:
php:
container_name: ${HOST_NAME}_php
image: quay.io/local-deploy/php${PHP_VERSION:-7.3-fpm}:${PHP_IMAGE_VERSION:-latest}
image: ${REPO}/local-deploy/php${PHP_VERSION:-7.4-fpm}:${PHP_IMAGE_VERSION:-latest}
environment:
- "DOCUMENT_ROOT=${DOCUMENT_ROOT:-/var/www/html}"
- "HOST_NAME=${HOST_NAME:-localhost}"
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/varrcan/dl/helper"
)

var version = "0.2.5"
var version = "0.2.6"

func main() {
if !helper.IsConfigDirExists() {
Expand Down Expand Up @@ -66,6 +66,7 @@ func createConfigFile() error {

viper.Set("version", version)
viper.Set("locale", "en")
viper.Set("repo", "ghcr.io")

errWrite := viper.SafeWriteConfig()

Expand Down
14 changes: 8 additions & 6 deletions project/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
var Env *viper.Viper

var phpImagesVersion = map[string]string{
"7.3-apache": "1.1.0",
"7.3-fpm": "1.0.0",
"7.4-apache": "1.0.1",
"7.4-fpm": "1.0.0",
"8.0-apache": "1.0.2",
"8.0-fpm": "1.0.1",
"7.3-apache": "1.1.1",
"7.3-fpm": "1.0.1",
"7.4-apache": "1.0.3",
"7.4-fpm": "1.0.1",
"8.0-apache": "1.0.3",
"8.0-fpm": "1.0.2",
}

// LoadEnv Get variables from .env file
Expand Down Expand Up @@ -74,6 +74,8 @@ func setDefaultEnv() {
Env.SetDefault("LOCAL_IP", host)
Env.SetDefault("NIP_DOMAIN", fmt.Sprintf("%s.%s.nip.io", projectName, host))
Env.SetDefault("LOCAL_DOMAIN", fmt.Sprintf("%s.localhost", projectName))

Env.SetDefault("REPO", viper.GetString("repo"))
}

// setComposeFile Set docker-compose files
Expand Down

0 comments on commit 6076446

Please sign in to comment.