Skip to content

Commit

Permalink
chore: remove network_mode: host
Browse files Browse the repository at this point in the history
  • Loading branch information
albttx committed Jan 26, 2024
1 parent 2c2b198 commit 414cf6d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 39 deletions.
16 changes: 5 additions & 11 deletions misc/loop/cmd/portalloopd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,13 @@ func (s *service) startPortalLoop(ctx context.Context, force bool) error {
return err
}
containers = []types.Container{*container}

for _, p := range container.Ports {
if p.Type == "tcp" && p.PrivatePort == uint16(26657) {
s.portalLoopURL = fmt.Sprintf("http://localhost:%d", int(p.PublicPort))
s.portalLoop.switchTraefikPortalLoop(s.portalLoopURL)
break
}
}
return nil
force = true
}

for _, p := range containers[0].Ports {
if p.Type == "tcp" && p.PrivatePort == uint16(26657) {
s.portalLoopURL = fmt.Sprintf("http://localhost:%d", int(p.PublicPort))
ip := containers[0].NetworkSettings.Networks["portal-loop"].IPAddress
s.portalLoopURL = fmt.Sprintf("http://%s:%d", ip, int(p.PrivatePort))
s.portalLoop.switchTraefikPortalLoop(s.portalLoopURL)
break
}
Expand Down Expand Up @@ -246,7 +239,8 @@ func (s *service) startPortalLoop(ctx context.Context, force bool) error {
}
for _, p := range container.Ports {
if p.Type == "tcp" && p.PrivatePort == uint16(26657) {
s.portalLoopURL = fmt.Sprintf("http://localhost:%d", int(p.PublicPort))
ip := containers[0].NetworkSettings.Networks["portal-loop"].IPAddress
s.portalLoopURL = fmt.Sprintf("http://%s:%d", ip, int(p.PrivatePort))
break
}
}
Expand Down
7 changes: 6 additions & 1 deletion misc/loop/cmd/portalloopd/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s snapshotter) switchTraefikPortalLoop(url string) error {
return err
}

regex := regexp.MustCompile(`http://localhost:[0-9]+`)
regex := regexp.MustCompile(`http://.*:[0-9]+`)
output := regex.ReplaceAllLiteral(input, []byte(url))

return ioutil.WriteFile(s.cfg.traefikGnoFile, output, 0655)
Expand Down Expand Up @@ -167,6 +167,11 @@ func (s snapshotter) startPortalLoopContainer(ctx context.Context) (*types.Conta
return nil, err
}

err = s.dockerClient.NetworkConnect(ctx, "portal-loop", container.ID, nil)
if err != nil {
return nil, err
}

if err := s.dockerClient.ContainerStart(ctx, container.ID, types.ContainerStartOptions{}); err != nil {
return nil, err
}
Expand Down
46 changes: 30 additions & 16 deletions misc/loop/docker-compose.production.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
version: "3"

networks:
portal-loop:
name: portal-loop
driver: bridge

services:
traefik:
image: "traefik:v2.10"
restart: unless-stopped
network_mode: host
container_name: "traefik"
command:
- "--api.insecure=true"
- "--providers.file=true"
- "--providers.file.watch=true"
- "--providers.file.directory=/etc/traefik/configs"
- "--entrypoints.web.address=:80"
- "--entrypoints.private.address=127.0.0.1:81"
- "--entrypoints.private.address=:81"
# - "--entrypoints.web.http.redirections.entrypoint.to=websecure"
# - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
# - "--entrypoints.web.http.redirections.entrypoint.permanent=true"
# - "--entryPoints.web.forwardedHeaders.insecure"
- "--entrypoints.traefik.address=:8080"
- "--entrypoints.traefik.address=127.0.0.1:8080"

- "--entrypoints.websecure.address=:443"
# - "--certificatesresolvers.le.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
- "[email protected]"
- "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json"
networks:
- portal-loop
ports:
# useless because of network_mode: host
# just here for readability
Expand All @@ -35,21 +40,20 @@ services:

gnoweb:
image: ghcr.io/gnolang/gno/gnoweb-slim
network_mode: host
restart: unless-stopped
entrypoint:
- gnoweb
- --bind=localhost:8888
- --remote=rpc.portal.gno.local:81
- --bind=0.0.0.0:8888
- --remote=traefik:81
# - --faucet-url="http://faucet.portal.gno.local:81"
- --faucet-url
- "http://localhost:9000"
# - --faucet-url
# - "http://localhost:9000"
- --help-chainid
- portal-loop
- --help-remote
- https://rpc.portal.gno.land:443
extra_hosts:
- rpc.portal.gno.local:127.0.0.1
networks:
- portal-loop

# gnofaucet:
# image: gnofaucet
Expand All @@ -67,28 +71,38 @@ services:
# - 5050

portalloopd:
image: ghcr.io/gnolang/gno/portalloopd
image: ghcr.io/albttx/gno/portalloopd
restart: unless-stopped
working_dir: /app
network_mode: host
volumes:
- ./scripts:/scripts
- ./backups:/backups
- ./traefik:/etc/traefik/configs
- "/var/run/docker.sock:/var/run/docker.sock:ro"
networks:
- portal-loop
ports:
- 9090:9090
- 127.0.0.1:9090:9090
environment:
HOST_PWD: $PWD
BACKUP_DIR: "/backups"
RPC_URL: "http://rpc.portal.gno.local:81"
RPC_URL: "http://traefik:81"
PROM_ADDR: "0.0.0.0:9090"
TRAEFIK_GNO_FILE: "/etc/traefik/configs/gno.yml"
extra_hosts:
- rpc.portal.gno.local:127.0.0.1
- host.docker.internal:host-gateway
labels:
- "com.centurylinklabs.watchtower.enable=false"

autocounterd:
image: ghcr.io/albttx/gno/autocounterd
restart: unless-stopped
environment:
COUNTER_MNEMONIC: "source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast"
COUNTER_RPC: "http://traefik:81"
networks:
- portal-loop

watchtower:
image: containrrr/watchtower
command: --interval 30 --http-api-metrics --label-enable
Expand Down
40 changes: 29 additions & 11 deletions misc/loop/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
version: "3"

networks:
portal-loop:
name: portal-loop
driver: bridge

services:
traefik:
image: "traefik:v2.10"
restart: unless-stopped
network_mode: host
container_name: "traefik"
command:
- "--api.insecure=true"
- "--providers.file=true"
Expand All @@ -13,6 +17,8 @@ services:
- "--entrypoints.web.address=:80"
- "--entrypoints.private.address=:81"
- "--entrypoints.traefik.address=:8080"
networks:
- portal-loop
ports:
# useless because of network_mode: host
# just here for readability
Expand All @@ -23,21 +29,22 @@ services:

gnoweb:
image: ghcr.io/gnolang/gno/gnoweb-slim
network_mode: host
restart: unless-stopped
networks:
- portal-loop
ports:
- 8888:8888
entrypoint:
- gnoweb
- --bind=localhost:8888
- --remote=rpc.portal.gno.local:81
- --bind=0.0.0.0:8888
- --remote=traefik:81
# - --faucet-url="http://faucet.portal.gno.local:81"
- --faucet-url
- "http://localhost:9000"
- --help-chainid
- portal-loop
- --help-remote
- https://rpc.portal.gno.land:443
extra_hosts:
- rpc.portal.gno.local:127.0.0.1

# gnofaucet:
# image: gnofaucet
Expand All @@ -59,20 +66,31 @@ services:
context: .
target: portalloopd
restart: unless-stopped
working_dir: /app
network_mode: host
volumes:
- ./scripts:/scripts
- ./backups:/backups
- ./traefik:/etc/traefik/configs
- "/var/run/docker.sock:/var/run/docker.sock:ro"
networks:
- portal-loop
ports:
- 9090:9090
environment:
HOST_PWD: $PWD
BACKUP_DIR: "/backups"
RPC_URL: "http://rpc.portal.gno.local:81"
RPC_URL: "http://traefik:81"
PROM_ADDR: "0.0.0.0:9090"
TRAEFIK_GNO_FILE: "/etc/traefik/configs/gno.yml"
extra_hosts:
- rpc.portal.gno.local:127.0.0.1
- host.docker.internal:host-gateway

autocounterd:
build:
context: .
target: autocounterd
restart: unless-stopped
environment:
COUNTER_MNEMONIC: "source bonus chronic canvas draft south burst lottery vacant surface solve popular case indicate oppose farm nothing bullet exhibit title speed wink action roast"
COUNTER_RPC: "http://traefik:81"
networks:
- portal-loop

0 comments on commit 414cf6d

Please sign in to comment.