Skip to content

Commit

Permalink
take vars from env, add deployment workflow to prod only
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Apr 11, 2024
1 parent 558e431 commit 81d6f98
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 42 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
docker push $GITHUB_REF_IMAGE
docker push $GITHUB_BRANCH_IMAGE
- name: Deploy on US server
if: github.ref == 'refs/heads/main'
if: github.ref == 'refs/heads/prod'
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.DEV_REMOTE_SERVER_ADDRESS_US01 }}
Expand All @@ -69,7 +69,7 @@ jobs:
docker pull ghcr.io/netsepio/erebrus:main
docker run -d -p 9080:9080/tcp -p 51820:51820/udp --cap-add=NET_ADMIN --cap-add=SYS_MODULE --sysctl="net.ipv4.conf.all.src_valid_mark=1" --sysctl="net.ipv6.conf.all.forwarding=1" --restart unless-stopped -v /home/ubuntu/erebrus/wireguard/:/etc/wireguard/ --name erebrus --env-file .env ghcr.io/netsepio/erebrus:main
- name: Deploy on EU server
if: github.ref == 'refs/heads/main'
if: github.ref == 'refs/heads/prod'
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.DEV_REMOTE_SERVER_ADDRESS_EU01 }}
Expand All @@ -84,7 +84,7 @@ jobs:
docker pull ghcr.io/netsepio/erebrus:main
docker run -d -p 9080:9080/tcp -p 51820:51820/udp --cap-add=NET_ADMIN --cap-add=SYS_MODULE --sysctl="net.ipv4.conf.all.src_valid_mark=1" --sysctl="net.ipv6.conf.all.forwarding=1" --restart unless-stopped -v /home/ubuntu/erebrus/wireguard/:/etc/wireguard/ --name erebrus --env-file .env ghcr.io/netsepio/erebrus:main
- name: Deploy on CA server
if: github.ref == 'refs/heads/main'
if: github.ref == 'refs/heads/prod'
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.DEV_REMOTE_SERVER_ADDRESS_CA01 }}
Expand All @@ -99,7 +99,7 @@ jobs:
docker pull ghcr.io/netsepio/erebrus:main
docker run -d -p 9080:9080/tcp -p 51820:51820/udp --cap-add=NET_ADMIN --cap-add=SYS_MODULE --sysctl="net.ipv4.conf.all.src_valid_mark=1" --sysctl="net.ipv6.conf.all.forwarding=1" --restart unless-stopped -v /home/ubuntu/erebrus/wireguard/:/etc/wireguard/ --name erebrus --env-file .env ghcr.io/netsepio/erebrus:main
- name: Deploy on SG server
if: github.ref == 'refs/heads/main'
if: github.ref == 'refs/heads/prod'
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.DEV_REMOTE_SERVER_ADDRESS_SG01 }}
Expand Down
1 change: 1 addition & 0 deletions p2p/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func makeBasicHost() (host.Host, error) {

func getHostAddress(ha host.Host) string {
// Build host multiaddress

hostAddr, _ := multiaddr.NewMultiaddr(fmt.Sprintf("/p2p/%s", ha.ID().String()))

// Now we can build a full multiaddress to reach this host
Expand Down
68 changes: 30 additions & 38 deletions p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import (
"os"
"time"

"github.com/NetSepio/erebrus/core"
"github.com/NetSepio/erebrus/util"
"github.com/NetSepio/erebrus/util/pkg/node"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/multiformats/go-multiaddr"
"github.com/sirupsen/logrus"
)

// DiscoveryInterval is how often we search for other peers via the DHT.
Expand Down Expand Up @@ -61,22 +59,16 @@ func Init() {
if err != nil {
panic(err)
}

go func() {
// do the interval task
status_data, err := core.GetServerStatus()
if err != nil {
logrus.WithFields(util.StandardFields).Error("Failed to get server status")
return
}
msgBytes, err := json.Marshal(status_data)
time.Sleep(5 * time.Second)
node_data := node.CreateNodeStatus(fullAddr, ha.ID().String())
msgBytes, err := json.Marshal(node_data)
if err != nil {
panic(err)
}
if err := topic.Publish(ctx, msgBytes); err != nil {
panic(err)
}
fmt.Println("send status")
}()
//Subscribe to the topic.
sub, err := topic.Subscribe()
Expand All @@ -99,35 +91,35 @@ func Init() {
}
}()

//Topic 2
topicString2 := "client" // Change "UniversalPeer" to whatever you want!
topic2, err := ps.Join(DiscoveryServiceTag + "/" + topicString2)
if err != nil {
panic(err)
}
// if err := topic2.Publish(ctx, []byte("sending data over client topic")); err != nil {
// //Topic 2
// topicString2 := "client" // Change "UniversalPeer" to whatever you want!
// topic2, err := ps.Join(DiscoveryServiceTag + "/" + topicString2)
// if err != nil {
// panic(err)
// }
// // if err := topic2.Publish(ctx, []byte("sending data over client topic")); err != nil {
// // panic(err)
// // }
// sub2, err := topic2.Subscribe()
// if err != nil {
// panic(err)
// }
sub2, err := topic2.Subscribe()
if err != nil {
panic(err)
}

go func() {
for {
// Block until we recieve a new message.
msg, err := sub2.Next(ctx)

if err != nil {
panic(err)
}
// if msg.ReceivedFrom == ha.ID() {
// continue
// }
fmt.Printf("[%s] %s", msg.ReceivedFrom, string(msg.Data))
fmt.Println()
}
}()
// go func() {
// for {
// // Block until we recieve a new message.
// msg, err := sub2.Next(ctx)

// if err != nil {
// panic(err)
// }
// // if msg.ReceivedFrom == ha.ID() {
// // continue
// // }
// fmt.Printf("[%s] %s", msg.ReceivedFrom, string(msg.Data))
// fmt.Println()
// }
// }()

}

Expand Down
22 changes: 22 additions & 0 deletions util/pkg/node/node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package node

import "os"

type NodeStatus struct {
Id string `json:"id"`
HttpPort string `json:"httpPort"`
Domain string `json:"domain"`
Address string `json:"address"`
Region string `json:"region"`
}

func CreateNodeStatus(address string, id string) *NodeStatus {
nodeStatus := &NodeStatus{
HttpPort: os.Getenv("HTTP_PORT"),
Domain: os.Getenv("DOMAIN"),
Address: address,
Region: os.Getenv("REGION"),
Id: id,
}
return nodeStatus
}

0 comments on commit 81d6f98

Please sign in to comment.