Something.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
ssh-key
|
||||
ssh-key.pub
|
||||
ssk-key.tar
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/client"
|
||||
)
|
||||
@@ -53,6 +54,16 @@ func Run(){
|
||||
http.HandleFunc("/services", listServices);
|
||||
http.HandleFunc("/prepare", prepare);
|
||||
http.HandleFunc("/cleanup", cleanup);
|
||||
|
||||
ApiClient.NetworkCreate(context.Background(), "blazenaPohar", network.CreateOptions{
|
||||
Attachable: true,
|
||||
// Internal: true,
|
||||
Driver: "overlay",
|
||||
Labels: map[string]string{
|
||||
"blazena.pohar": "true",
|
||||
},
|
||||
});
|
||||
|
||||
go func(){
|
||||
err = server.ListenAndServe();
|
||||
if err == http.ErrServerClosed {
|
||||
@@ -69,6 +80,7 @@ func Run(){
|
||||
<-ctx.Done();
|
||||
fmt.Println("Stopping http server.");
|
||||
server.Close();
|
||||
ApiClient.NetworkRemove(context.Background(), "blazenaPohar");
|
||||
fmt.Println("Exiting!");
|
||||
}
|
||||
|
||||
|
||||
@@ -51,9 +51,7 @@ func prepare(w http.ResponseWriter, r *http.Request){
|
||||
maxConcurrent := uint64(1);
|
||||
totalCompletions := uint64(1);
|
||||
targetNode := labels["blazena.node"];
|
||||
helperCommand := `apk add openssh rsync && \
|
||||
ssh-keygen -t ed25519 -f /host_key && \
|
||||
mkdir -p /root/.ssh/ && \
|
||||
helperCommand := `ssh-keygen -t ed25519 -f /host_key && \
|
||||
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIByYbl8vu946LPycSO5pBohq3vMvvl+wX7snu1Bqpd7p test" > /root/.ssh/authorized_keys && \
|
||||
/usr/sbin/sshd -h /host_key -p 22 -D`;
|
||||
|
||||
@@ -70,7 +68,7 @@ func prepare(w http.ResponseWriter, r *http.Request){
|
||||
},
|
||||
TaskTemplate: swarm.TaskSpec{
|
||||
ContainerSpec: &swarm.ContainerSpec{
|
||||
Image: "docker.io/library/alpine:latest",
|
||||
Image: "registry.lan.ronycloud.dev/blazena/helper:latest",
|
||||
Command: []string{"sh", "-c", helperCommand},
|
||||
Mounts: []mount.Mount{
|
||||
mount.Mount{
|
||||
|
||||
@@ -18,6 +18,7 @@ func scaleDown(serviceId string){
|
||||
|
||||
newScale := uint64(0);
|
||||
updatedSpec.Mode.Replicated.Replicas = &newScale;
|
||||
updatedSpec.Labels["blazena.scaledDown"] = "true";
|
||||
|
||||
scale.Store(serviceId, *originalScale);
|
||||
|
||||
@@ -46,6 +47,7 @@ func scaleUp(serviceId string){
|
||||
updatedSpec := inspectresoult.Spec;
|
||||
|
||||
updatedSpec.Mode.Replicated.Replicas = &originalScaleChecked;
|
||||
delete(updatedSpec.Labels, "blazena.scaledDown");
|
||||
|
||||
ApiClient.ServiceUpdate(context.Background(), serviceId, inspectresoult.Version, updatedSpec, swarm.ServiceUpdateOptions{});
|
||||
}
|
||||
|
||||
4
helper.Dockerfile
Normal file
4
helper.Dockerfile
Normal file
@@ -0,0 +1,4 @@
|
||||
FROM alpine:3
|
||||
|
||||
RUN mkdir -p /root/.ssh/
|
||||
RUN apk add openssh rsync --no-cache
|
||||
53
host/host.go
53
host/host.go
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
@@ -46,16 +47,37 @@ func Run(Config cfg.Config) {
|
||||
fmt.Println("Preparing: " + service.ServiceId + " volume: " + volume);
|
||||
if !prepareService(Config, service, volume) {continue}
|
||||
fmt.Println("Done!");
|
||||
time.Sleep(5*time.Second);
|
||||
fmt.Println("Cleaning Up: " + service.ServiceId + " volume: " + volume);
|
||||
|
||||
command := `apk add --no-cache rsync openssh-client && \
|
||||
echo "It Works Under Water!"`;
|
||||
//rsync -avz --delete -e "ssh -i /ssh-key -p 2222 -o StrictHostKeyChecking=no" \
|
||||
//root@`+Config.Nodes[service.Node].Ip+`:/volume/ /tmp`
|
||||
|
||||
|
||||
time.Sleep(15*time.Second);
|
||||
exec, err := DockerClient.ContainerExecCreate(context.Background(), "BlazenaStorage", container.ExecOptions{
|
||||
Cmd: []string{"sh", "-c", command},
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
Tty: false,
|
||||
});
|
||||
if err != nil {
|
||||
panic("Failed to create rsync exec!"+err.Error());
|
||||
}
|
||||
|
||||
|
||||
resp, err := DockerClient.ContainerExecAttach(context.Background(), exec.ID, container.ExecStartOptions{});
|
||||
defer resp.Close();
|
||||
|
||||
io.Copy(os.Stdout, resp.Reader)
|
||||
|
||||
fmt.Println("Cleaning Up: " + service.ServiceId);
|
||||
cleanupService(Config, service);
|
||||
fmt.Println("Done!");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
time.Sleep(15*time.Second);
|
||||
DockerClient.ContainerRemove(context.Background(), "BlazenaStorage", container.RemoveOptions{
|
||||
Force: true,
|
||||
});
|
||||
@@ -169,7 +191,7 @@ func createStorageContainer(Config cfg.Config, DockerClient *client.Client){
|
||||
Labels: map[string]string{
|
||||
"blazena.storage": "true",
|
||||
},
|
||||
Cmd: strslice.StrSlice{"sleep", "infinity"},
|
||||
Cmd: strslice.StrSlice{"sleep", "1h"},
|
||||
}, &container.HostConfig{
|
||||
Mounts: []mount.Mount{
|
||||
mount.Mount{
|
||||
@@ -180,7 +202,7 @@ func createStorageContainer(Config cfg.Config, DockerClient *client.Client){
|
||||
},
|
||||
},
|
||||
//AutoRemove: true,
|
||||
NetworkMode: "blazena",
|
||||
NetworkMode: "blazenaPohar",
|
||||
}, &network.NetworkingConfig{
|
||||
}, &v1.Platform{}, "BlazenaStorage");
|
||||
|
||||
@@ -194,4 +216,21 @@ func createStorageContainer(Config cfg.Config, DockerClient *client.Client){
|
||||
panic("Failed to start BlazenaStorage container!"+err.Error());
|
||||
}
|
||||
|
||||
|
||||
reader, err := os.Open("./ssh-key.tar");
|
||||
|
||||
if err != nil {
|
||||
panic("Failed To open ssh key file for reading!"+err.Error());
|
||||
}
|
||||
|
||||
defer reader.Close();
|
||||
|
||||
err = DockerClient.CopyToContainer(context.Background(), "BlazenaStorage", "/", reader, container.CopyToContainerOptions{
|
||||
AllowOverwriteDirWithFile: true,
|
||||
});
|
||||
if err != nil {
|
||||
panic("Failed to copy ssh key to container!"+err.Error());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user