Skip to content

Commit

Permalink
mirror server
Browse files Browse the repository at this point in the history
  • Loading branch information
archmagece committed Aug 27, 2024
1 parent f9486f9 commit efc7cd9
Show file tree
Hide file tree
Showing 35 changed files with 354 additions and 190 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ vendor/

# test
tmp/

~tmp/
~/
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# 모은다

## Stacks
- gin-gonic/gin
# Proxy 해주는거

## 용도

Proxy, Mirror를 같이 하려고 했는데... 귀찮아서 proxy만 남길 예정
- [x] Maven Proxy
- [ ] Maven Mirror
- [x] Apt Proxy
- [ ] Apt Mirror

- [x] Maven
- [x] Apt
- [ ] Npm
- [ ] Go
- [ ] Python
Expand All @@ -26,6 +24,7 @@ Proxy, Mirror를 같이 하려고 했는데... 귀찮아서 proxy만 남길 예
## 쓰면 나쁨점
한번하면 되지만 설치는 귀찮음
지원되는게 별로 없음
home 디렉토리 날라감

## 초기설정시

Expand Down Expand Up @@ -95,6 +94,12 @@ servers:
# username:
```

## 캐시 초기화 명령어 ^^

```bash
rm -rf ~
```

## REF

maven
Expand Down
2 changes: 1 addition & 1 deletion conf/mirror-apt.yaml → conf/apt-mirror.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
path: ~/tmp/mirror/apt
path: mirror/apt

mirrors:
ubuntu:
Expand Down
8 changes: 6 additions & 2 deletions conf/proxy-apt.yaml → conf/apt-proxy.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
path: ~/tmp/proxy/apt
use_cache: true
path: proxy/apt

#cache:
# enabled: false
# retention_time: 1h
# evict: 1h

proxies:
ubuntu:
Expand Down
26 changes: 26 additions & 0 deletions conf/github-mirror.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#path: ~/tmp/mirror/git
#
#workpath: ~/mymirror
#
## naming은... github/{user}/{repo}를 기본으로
## 아니면
## repoanme만 쓸 수 있으면 쓰고..
## {user}-{repo} 안되는 경우
#
#mirrors:
# github:
# zitryss:
# groups: ['go']
# repos:
# go-sample:
# # branch: master
# groups: ['git', 'go']
# PersonaIam:
# groups: ['coin']
# repos:
# persona-client:
# groups: ['coin', 'go']
# streamlit:
# groups: ['coin', 'python']
# repos:
# streamlit:
17 changes: 7 additions & 10 deletions conf/global.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
base_dir: ~/tmp
config_dir: ~/tmp/config
#proxy:
# http: 192.168.11.99:3128
# https: 192.168.11.99:3129

proxy:
http: 192.168.11.99:3128
https: 192.168.11.99:3129

cache_enabled: false
cache_dir: ~/tmp/cache
mirror_enabled: false
mirror_dir: ~/tmp/mirror
#if base_dir set? proxy, mirror relative
base_dir: ~/tmp/deproxy
#proxy_root: ~/tmp/proxy
#mirror_root: ~/tmp/mirror
9 changes: 0 additions & 9 deletions conf/host-maven.yaml

This file was deleted.

9 changes: 9 additions & 0 deletions conf/maven-host.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#path: ~/tmp/data/maven/
#
#repositories:
# company-dev:
# snapshot: true
# overwrite: true
# company-prd:
# snapshot: false
# overwrite: false
2 changes: 1 addition & 1 deletion conf/mirror-maven.yaml → conf/maven-mirror.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
path: tmp/cachedir/mirror/maven
path: mirror/maven
use_cache: true
# https://docs.gradle.org/current/userguide/declaring_repositories.html

Expand Down
2 changes: 1 addition & 1 deletion conf/proxy-maven.yaml → conf/maven-proxy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
path: tmp/cachedir/proxy/maven
path: proxy/maven
use_cache: true
# https://docs.gradle.org/current/userguide/declaring_repositories.html

Expand Down
26 changes: 0 additions & 26 deletions conf/mirror-github.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions conf/proxy-vagrant.yaml

This file was deleted.

40 changes: 20 additions & 20 deletions conf/users.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
users:
- name: admin
password: passw0rd
roles: [ admin ]
- name: user
password: passw0rd
roles: [ user, deploy ]

roles:
admin:
permissions:
- *
developer:
permissions:
- read
- write
- deploy
deployer:
permissions:
- deploy
#users:
# - name: admin
# password: passw0rd
# roles: [ admin ]
# - name: user
# password: passw0rd
# roles: [ user, deploy ]
#
#roles:
# admin:
# permissions:
# - *
# developer:
# permissions:
# - read
# - write
# - deploy
# deployer:
# permissions:
# - deploy
8 changes: 8 additions & 0 deletions conf/vagrant-proxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#cache:
# relative: false
# path: /proxy/vagrant
#
#servers:
# - id: official
# name: Official
# url: http://official
10 changes: 6 additions & 4 deletions configs/apt_mirror_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package configs

import (
"deproxy/helpers"
"path"
)

type AptMirror struct {
URL string `json:"url"`
URL string `json:"url,omitempty"`
}

type AptMirrors struct {
Expand All @@ -14,10 +15,11 @@ type AptMirrors struct {
}

type AptMirrorConfig struct {
Path string `json:"path"`
Path string `json:"path,omitempty"`
Mirrors AptMirrors `json:"mirrors"`
}

func (cfg *AptMirrorConfig) ReadConfig(path string) {
helpers.ReadYaml(path, cfg)
func (cfg *AptMirrorConfig) ReadConfig() {
confDir := helpers.GetEnv("CONFIG_DIR", "conf/")
helpers.ReadYaml(path.Join(confDir, "apt-mirror.yaml"), cfg)
}
4 changes: 3 additions & 1 deletion configs/apt_mirror_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"deproxy/helpers"
"fmt"
"github.com/go-playground/assert/v2"
"os"
"testing"
)

func TestAptMirrorConfig_ReadConfig(t *testing.T) {
os.Setenv("CONFIG_DIR", "../conf/")
cfg := AptMirrorConfig{}
cfg.ReadConfig("../conf/mirror-apt.yaml")
cfg.ReadConfig()
fmt.Println(cfg)
assert.Equal(t, cfg.Path, "~/tmp/mirror/apt")
fmt.Println(helpers.ToStringYaml(cfg))
Expand Down
19 changes: 13 additions & 6 deletions configs/apt_proxy_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@ package configs

import (
"deproxy/helpers"
"path"
)

type AptProxy struct {
Name string `json:"name"`
URL string `json:"url"`
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
}

type AptProxyConfig struct {
Path string `json:"path"`
UserCache string `json:"user_cache"`
Path string `json:"path,omitempty"`
UserCache bool `json:"user_cache,omitempty" default:false`
Proxies map[string][]AptProxy `json:"proxies"`
}

func (cfg *AptProxyConfig) ReadConfig(path string) {
helpers.ReadYaml(path, cfg)
func (cfg *AptProxyConfig) ConfigExists() bool {
confDir := helpers.GetEnv("CONFIG_DIR", "conf/")
return helpers.FileExists(path.Join(confDir, "apt-proxy.yaml"))
}

func (cfg *AptProxyConfig) ReadConfig() {
confDir := helpers.GetEnv("CONFIG_DIR", "conf/")
helpers.ReadYaml(path.Join(confDir, "apt-proxy.yaml"), cfg)
}
4 changes: 3 additions & 1 deletion configs/apt_proxy_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"deproxy/helpers"
"fmt"
"github.com/go-playground/assert/v2"
"os"
"testing"
)

func TestAptProxyConfig_ReadConfig(t *testing.T) {
os.Setenv("CONFIG_DIR", "../conf/")
cfg := AptProxyConfig{}
cfg.ReadConfig("../conf/proxy-apt.yaml")
cfg.ReadConfig()
fmt.Println(cfg)
assert.Equal(t, cfg.Path, "~/tmp/proxy/apt")
fmt.Println(helpers.ToStringYaml(cfg))
Expand Down
24 changes: 24 additions & 0 deletions configs/global_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package configs

import (
"deproxy/helpers"
"path"
"strings"
)

type GlobalConfig struct {
BaseDir string `yaml:"base_dir,omitempty"`
//ConfigDir string `yaml:"config_dir,omitempty"`
}

func (cfg *GlobalConfig) ReadConfig() {
confDir := helpers.GetEnv("CONFIG_DIR", "conf/")
helpers.ReadYaml(path.Join(confDir, "global.yaml"), cfg)

if cfg.BaseDir == "" {
cfg.BaseDir = "~/tmp/deproxy"
}
if strings.HasPrefix(cfg.BaseDir, "~") {
cfg.BaseDir = helpers.ExpandHome(cfg.BaseDir)
}
}
18 changes: 18 additions & 0 deletions configs/global_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package configs

import (
"deproxy/helpers"
"fmt"
"github.com/go-playground/assert/v2"
"os"
"testing"
)

func TestRead_GlobalConfig(t *testing.T) {
os.Setenv("CONFIG_DIR", "../conf/")
cfg := GlobalConfig{}
cfg.ReadConfig()
assert.Equal(t, cfg.BaseDir, "~/tmp/deproxy")
//assert.Equal(t, cfg.ConfigDir, "~/tmp/config")
fmt.Println(helpers.ToStringYaml(cfg))
}
12 changes: 7 additions & 5 deletions configs/maven_mirror_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ package configs

import (
"deproxy/helpers"
"path"
)

type MavenMirrorServer struct {
Name string `yaml:"name"`
Url string `yaml:"url"`
Url string `yaml:"url,omitempty"`
Description string `yaml:"description"`
}

type MavenMirrorConfig struct {
Path string `yaml:"path"`
UseCache bool `yaml:"use_cache"`
Path string `yaml:"path,omitempty"`
UseCache bool `yaml:"use_cache,omitempty"`
Mirrors map[string]MavenMirrorServer `yaml:"mirrors"`
}

func (cfg *MavenMirrorConfig) ReadConfig(path string) {
helpers.ReadYaml(path, cfg)
func (cfg *MavenMirrorConfig) ReadConfig() {
confDir := helpers.GetEnv("CONFIG_DIR", "conf/")
helpers.ReadYaml(path.Join(confDir, "maven-mirror.yaml"), cfg)
}
Loading

0 comments on commit efc7cd9

Please sign in to comment.