Skip to content

Commit 6e10ff1

Browse files
committed
Added Dockerfile, Migrated Configs to ENV and Composed Publish Workflow.
1 parent b7cd7d0 commit 6e10ff1

File tree

6 files changed

+75
-14
lines changed

6 files changed

+75
-14
lines changed

.github/workflows/publish.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
jobs:
9+
main-workflow:
10+
uses: Evolutionary-Algorithms-On-Click/operations/.github/workflows/docker-publish.yml@main
11+
with:
12+
branch: ${{ github.ref }}
13+
image_name: ${{ github.repository }}
14+
event_name: ${{ github.event_name }}
15+
permissions:
16+
contents: read
17+
packages: write
18+
id-token: write

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# golang 1.23
2+
FROM golang:1.23
3+
4+
# Set the Current Working Directory inside the container
5+
WORKDIR /runner_controller_microservice
6+
7+
# Copy go mod and sum files
8+
COPY go.mod go.sum ./
9+
10+
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
11+
RUN go mod download
12+
13+
# Copy the source from the current directory to the Working Directory inside the container
14+
COPY . .
15+
16+
# Build the Go app
17+
RUN go build -o main .
18+
19+
# This container exposes port 5002 to the outside world
20+
EXPOSE 5002
21+
22+
# Command to run the executable
23+
CMD ["./main"]

config/default.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
services:
3+
auth:
4+
image: ghcr.io/evolutionary-algorithms-on-click/runner_controller_microservice:main
5+
ports:
6+
- "5002:5002"
7+
environment:
8+
DATABASE_URL : postgresql://[email protected]:26257/defaultdb?sslmode=disable
9+
MINIO_ENDPOINT : host.docker.internal:9000
10+
MINIO_ACCESS_KEY_ID : <MINIO_ACCESS_KEY_ID>
11+
MINIO_SECRET_KEY : <MINIO_SECRET_KEY>
12+
RABBITMQ_URL : amqp://<user>:<password>@host.docker.internal:5672/
13+
FRONTEND_URL : http://host.docker.internal:3000
14+
HTTP_PORT : 5002
15+
AUTH_GRPC_ADDRESS : host.docker.internal:5001

main.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
package main
22

33
import (
4-
"evolve/config"
4+
// "evolve/config"
55
"evolve/controller"
66
"evolve/routes"
77
"evolve/util"
88
"fmt"
9+
"github.com/rs/cors"
910
"net/http"
11+
"os"
12+
)
1013

11-
"github.com/rs/cors"
14+
var (
15+
PORT string
16+
FRONTEND_URL string
1217
)
1318

1419
func main() {
20+
21+
PORT = fmt.Sprintf(":%s", os.Getenv("HTTP_PORT"))
22+
FRONTEND_URL = os.Getenv("FRONTEND_URL")
23+
1524
var logger = util.NewLogger()
1625

1726
// Register routes.
@@ -24,15 +33,15 @@ func main() {
2433
http.HandleFunc(routes.SHARE_RUN, controller.ShareRun)
2534
http.HandleFunc(routes.RUN, controller.UserRun)
2635

27-
logger.Info(fmt.Sprintf("Test http server on http://localhost%v/api/test", config.PORT))
36+
logger.Info(fmt.Sprintf("Test http server on http://localhost%v/api/test", PORT))
2837

2938
corsHandler := cors.New(cors.Options{
30-
AllowedOrigins: []string{"http://localhost:3000"},
39+
AllowedOrigins: []string{FRONTEND_URL},
3140
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
3241
AllowedHeaders: []string{"*"},
3342
AllowCredentials: true,
3443
}).Handler(http.DefaultServeMux)
35-
if err := http.ListenAndServe(config.PORT, corsHandler); err != nil {
44+
if err := http.ListenAndServe("0.0.0.0"+PORT, corsHandler); err != nil {
3645
logger.Error(fmt.Sprintf("Failed to start server: %v", err))
3746
return
3847
}

modules/auth.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package modules
22

33
import (
44
"context"
5-
"evolve/config"
65
pb "evolve/proto"
76
"evolve/util"
87
"fmt"
98
"net/http"
9+
"os"
10+
11+
// "os"
1012
"time"
1113

1214
"google.golang.org/grpc"
@@ -27,15 +29,15 @@ func Auth(req *http.Request) (map[string]string, error) {
2729

2830
// Verify the token via a gRPC call
2931
// to the auth micro-service.
30-
authConn, err := grpc.NewClient(config.AUTH_GRPC_ADDRESS, grpc.WithTransportCredentials(insecure.NewCredentials()))
32+
authConn, err := grpc.NewClient(os.Getenv("AUTH_GRPC_ADDRESS"), grpc.WithTransportCredentials(insecure.NewCredentials()))
3133
if err != nil {
3234
logger.Error(fmt.Sprintf("Failed to create gRPC client: %v", err))
3335
return nil, fmt.Errorf("something went wrong")
3436
}
3537
defer authConn.Close()
3638

3739
authClient := pb.NewAuthenticateClient(authConn)
38-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
40+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
3941
defer cancel()
4042

4143
r, err := authClient.Auth(ctx, &pb.TokenValidateRequest{Token: token.Value})

0 commit comments

Comments
 (0)