add dockerfile for cli and add to drone
This commit is contained in:
parent
70d306d0d2
commit
899805ddac
4 changed files with 41 additions and 8 deletions
8
cli/Dockerfile
Normal file
8
cli/Dockerfile
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
FROM golang:alpine
|
||||
RUN mkdir /app
|
||||
ADD . /app/
|
||||
WORKDIR /app
|
||||
RUN go build -o main .
|
||||
RUN adduser -S -D -H -h /app appuser
|
||||
USER appuser
|
||||
CMD ["./main"]
|
||||
|
|
@ -23,7 +23,7 @@ var (
|
|||
|
||||
type GitFS struct {
|
||||
repo *git.Repository
|
||||
fs billy.Filesystem
|
||||
fs *billy.Filesystem
|
||||
auth *http.BasicAuth
|
||||
}
|
||||
|
||||
|
|
@ -34,17 +34,19 @@ func NewGitFS(repoURL string) (*GitFS, error) {
|
|||
Password: gitToken,
|
||||
}
|
||||
storer := memory.NewStorage()
|
||||
fs := memfs.New()
|
||||
|
||||
r, err := git.Clone(storer, g.fs, &git.CloneOptions{
|
||||
r, err := git.Clone(storer, fs, &git.CloneOptions{
|
||||
URL: repository,
|
||||
Auth: auth,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to clone repo from repo url '%s'", repoURL)
|
||||
}
|
||||
return &GitFS{repo: r, fs: memfs.New(), auth: auth}, nil
|
||||
return &GitFS{repo: r, fs: &fs, auth: auth}, nil
|
||||
}
|
||||
|
||||
func (g *GitFS) Push() error {
|
||||
glog.Infof("Attemping to push with auth: %+v", g.auth)
|
||||
return g.repo.Push(&git.PushOptions{Auth: g.auth})
|
||||
}
|
||||
|
|
|
|||
11
cli/vpn.go
11
cli/vpn.go
|
|
@ -15,8 +15,8 @@ const (
|
|||
vpnUseCaseFlagName = "vpn"
|
||||
vpnClientNameFlagName = "vpn-client-name"
|
||||
vpnClientPubKeyFlagName = "vpn-pub-key"
|
||||
vpnClientsConfFileRelative = "modules/kubernetes/wireguard/extra/clients.conf"
|
||||
vpnLastIPConfFileRelative = "modules/kubernetes/wireguard/extra/last_ip.txt"
|
||||
vpnClientsConfFileRelative = "/modules/kubernetes/wireguard/extra/clients.conf"
|
||||
vpnLastIPConfFileRelative = "/modules/kubernetes/wireguard/extra/last_ip.txt"
|
||||
)
|
||||
|
||||
// addVPNClient inserts new client config
|
||||
|
|
@ -29,7 +29,7 @@ func addVPNClient(gitFs *GitFS, clientName, publicKey, clientsConfPath, ip strin
|
|||
}
|
||||
contents := "[Peer]\n# friendly_name = " + clientName + "\nPublicKey = " + publicKey + "\nAllowedIPs = " + ip + "\n\n"
|
||||
glog.Infof("adding the following config: \n%s", contents)
|
||||
f, err := gitFs.fs.OpenFile(clientsConfPath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
|
||||
f, err := (*gitFs.fs).OpenFile(clientsConfPath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to open client configs file to add new vpn client")
|
||||
}
|
||||
|
|
@ -63,7 +63,8 @@ func incrementIP(origIP, cidr string) (string, error) {
|
|||
|
||||
// getAndUpdateIP Reads `fileName`, tries to get the ip, increments it, tries to write it back and returns the new address
|
||||
func getAndUpdateIP(gitFs *GitFS, fileName string) (string, error) {
|
||||
bytes, err := ioutil.ReadFile(fileName)
|
||||
f, err := (*gitFs.fs).Open(fileName)
|
||||
bytes, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "filed to read file %s", fileName)
|
||||
}
|
||||
|
|
@ -87,7 +88,7 @@ func getAndUpdateIP(gitFs *GitFS, fileName string) (string, error) {
|
|||
|
||||
// Write back updated ip
|
||||
fileContents := fmt.Sprintf("# DO NOT MANUALLY EDIT THIS LINE. Last IP: %s", incrementedIP+"/"+cidr)
|
||||
f, err := gitFs.fs.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, 0644)
|
||||
f, err = (*gitFs.fs).OpenFile(fileName, os.O_WRONLY|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to open file %s for writing", fileName)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue