Skip to content

Commit

Permalink
optimize dockerfile, workflow: add fixed identity key
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Apr 8, 2024
1 parent 91ff1b3 commit 76d239c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
docker stop erebrus-gateway && docker rm erebrus-gateway && docker image rm ghcr.io/netsepio/erebrus-gateway:main
echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
docker pull ghcr.io/netsepio/erebrus-gateway:main
docker run --restart=on-failure:14 --dns=1.1.1.1 --name="erebrus-gateway" --env-file=.env -p 9000:9000 -p 9001:9001 --net=bridge -d ghcr.io/netsepio/erebrus-gateway:main
docker run --restart=on-failure:14 --dns=1.1.1.1 --name="erebrus-gateway" --env-file=.env -p 9000:9000 -p 9001:9001 --net=bridge -v "$(pwd)/identity.key:/app/identity.key" -d ghcr.io/netsepio/erebrus-gateway:main
- name: Deploy on PROD server
if: github.ref == 'refs/heads/prod'
uses: appleboy/ssh-action@v0.1.7
Expand All @@ -61,5 +61,5 @@ jobs:
docker stop erebrus-gateway && docker rm erebrus-gateway && docker image rm ghcr.io/netsepio/erebrus-gateway:prod
echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin
docker pull ghcr.io/netsepio/erebrus-gateway:prod
docker run --restart=on-failure:14 --dns=1.1.1.1 --name="erebrus-gateway" --env-file=.env -p 9000:9000 -p 9001:9001 --net=bridge -d ghcr.io/netsepio/erebrus-gateway:prod
docker run --restart=on-failure:14 --dns=1.1.1.1 --name="erebrus-gateway" --env-file=.env -p 9000:9000 -p 9001:9001 --net=bridge -v "$(pwd)/identity.key:/app/identity.key" -d ghcr.io/netsepio/erebrus-gateway:prod
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Build stage
FROM golang:alpine AS build-app
WORKDIR /app
RUN apk update && apk add --no-cache git
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN go build -o erebrus-gateway . && apk del git
RUN go build -o erebrus-gateway .

FROM alpine AS final
WORKDIR /app
COPY --from=build-app /app/erebrus-gateway .
RUN apk del git
CMD ["./erebrus-gateway"]
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"github.com/NetSepio/erebrus-gateway/api/status"
"github.com/NetSepio/erebrus-gateway/api/v1/client"
nodes "github.com/NetSepio/erebrus-gateway/api/v1/node"
"github.com/NetSepio/erebrus-gateway/api/v1/nodes"
"github.com/gin-gonic/gin"
)

Expand Down
4 changes: 2 additions & 2 deletions api/v1/node/node.go → api/v1/nodes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
)

func ApplyRoutes(r *gin.RouterGroup) {
g := r.Group("/node")
g := r.Group("/nodes")
{
g.Use(paseto.PASETO(false))
g.POST("/all", FetchAllNodes)
g.GET("/all", FetchAllNodes)
}
}

Expand Down
14 changes: 7 additions & 7 deletions app/p2p-Node/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ func SubscribeTopics(ps *pubsub.PubSub, h host.Host, ctx context.Context) {
func CreateOrUpdate(db *gorm.DB, node *models.Node) error {
var model models.Node

if err := db.First(&model, node.Id).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return db.Create(node).Error
}
return err
result := db.Model(&models.Node{}).Where("id = ?", node.Id)
if result.RowsAffected != 0 {
//exists, update
return db.Model(&model).Updates(node).Error
} else {
//create
return db.Create(node).Error
}

return db.Model(&model).Updates(node).Error
}

0 comments on commit 76d239c

Please sign in to comment.