From 72d5d8df88d250d8e614cea943b8dbc2c47f251c Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sat, 27 Jul 2024 16:13:08 +0330 Subject: [PATCH 01/41] add initial files --- Dockerfile | 42 ++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 38 ++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1deb02f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM golang:1.22.4-bullseye as builder +# FROM registry.docker.ir/golang:1.22.4-alpine as builder + +ARG FOLDER_NAME +# ENV FOLDER_NAME=$FOLDER_NAME + +ENV APP_HOME /app/ + +WORKDIR "$APP_HOME" + +COPY go.mod ./ +RUN go mod download + + +COPY ${FOLDER_NAME} . +COPY common . +COPY adserver/.env adserver +COPY eventserver/.env eventserver +COPY panel/.env panel +COPY publisherwebsite/.env publisherwebsite + +RUN go mod verify +WORKDIR ${FOLDER_NAME} +RUN go build -o ${FOLDER_NAME}.out + +# FROM registry.docker.ir/golang:1.22.4-alpine +FROM golang:1.22.4-bullseye + +ENV APP_HOME /app/${FOLDER_NAME} +RUN mkdir -p "$APP_HOME" +WORKDIR "$APP_HOME" + +# COPY src/conf/ conf/ +# COPY src/views/ views/ +COPY --from=builder "$APP_HOME"/${FOLDER_NAME}.out $APP_HOME +COPY --from=builder "$APP_HOME"/adserver $APP_HOME +COPY --from=builder "$APP_HOME"/eventserver $APP_HOME +COPY --from=builder "$APP_HOME"/panel $APP_HOME +COPY --from=builder "$APP_HOME"/publisherwebsite $APP_HOME + +EXPOSE 8083 +CMD ["./${FOLDER_NAME}.out"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7d0db4c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.8' + +services: + panel: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=panel + ports: + - "8083:8083" + env_file: + - ./panel/.env + volumes: + - "panel_static:/app/panel/static" + depends_on: + db: + condition: service_healthy + db: + image: 'postgres:15.7-alpine' + environment: + - 'POSTGRES_DB=?' + - 'POSTGRES_USER=?' + - 'POSTGRES_PASSWORD=?' + ports: + - '5433:5432' + restart: unless-stopped + volumes: + - "postgres_data:/var/lib/postgresql/data" + healthcheck: + test: [ "CMD-SHELL", "pg_isready", "-d", "db_prod" ] + interval: 30s + timeout: 60s + retries: 5 + start_period: 80s +volumes: + panel_static: + postgres_data: diff --git a/go.mod b/go.mod index d977007..e5c010b 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module YellowBloomKnapsack/mini-yektanet go 1.22.4 require ( - github.com/beevik/guid v1.0.0 + // github.com/beevik/guid v1.0.0 github.com/gin-contrib/cors v1.7.2 github.com/gin-gonic/gin v1.10.0 github.com/joho/godotenv v1.5.1 From 3cf758752568884f718ceba7d50c32d0c2c7ae0b Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sat, 27 Jul 2024 17:03:29 +0330 Subject: [PATCH 02/41] add arg for second stage --- Dockerfile | 2 +- copyenvs.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100755 copyenvs.sh diff --git a/Dockerfile b/Dockerfile index 1deb02f..7201f56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN go build -o ${FOLDER_NAME}.out # FROM registry.docker.ir/golang:1.22.4-alpine FROM golang:1.22.4-bullseye - +ARG FOLDER_NAME ENV APP_HOME /app/${FOLDER_NAME} RUN mkdir -p "$APP_HOME" WORKDIR "$APP_HOME" diff --git a/copyenvs.sh b/copyenvs.sh new file mode 100755 index 0000000..8c07a14 --- /dev/null +++ b/copyenvs.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +scp -P 2233 panel/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/panel/.env +scp -P 2233 adserver/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/adserver/.env +scp -P 2233 common/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/common/.env +scp -P 2233 eventserver/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/eventserver/.env +scp -P 2233 publisherwebsite/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/publisherwebsite/.env \ No newline at end of file From 55b21859b29981fbc0737c68a797120f6179b94e Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sat, 27 Jul 2024 19:02:45 +0330 Subject: [PATCH 03/41] add docker and docker-compose --- Dockerfile | 48 +++++++++++++++++++++++++++++----------------- docker-compose.yml | 9 ++++----- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7201f56..e60f826 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,41 +2,53 @@ FROM golang:1.22.4-bullseye as builder # FROM registry.docker.ir/golang:1.22.4-alpine as builder ARG FOLDER_NAME +ARG PORT_NUMBER # ENV FOLDER_NAME=$FOLDER_NAME +ENV BUILDER_HOME /app/ -ENV APP_HOME /app/ - -WORKDIR "$APP_HOME" +WORKDIR "$BUILDER_HOME" COPY go.mod ./ RUN go mod download -COPY ${FOLDER_NAME} . -COPY common . -COPY adserver/.env adserver -COPY eventserver/.env eventserver -COPY panel/.env panel -COPY publisherwebsite/.env publisherwebsite +COPY ${FOLDER_NAME} ./${FOLDER_NAME} +COPY common ./common +COPY adserver/.env adserver/.env +COPY eventserver/.env eventserver/.env +COPY panel/.env panel/.env +COPY publisherwebsite/.env publisherwebsite/.env +COPY go.sum ./ RUN go mod verify WORKDIR ${FOLDER_NAME} -RUN go build -o ${FOLDER_NAME}.out +RUN go build -o output.out # FROM registry.docker.ir/golang:1.22.4-alpine FROM golang:1.22.4-bullseye ARG FOLDER_NAME +ENV envFOLDER_NAME=$FOLDER_NAME +RUN mkdir -p /app ENV APP_HOME /app/${FOLDER_NAME} +ENV BUILDER_HOME /app/ RUN mkdir -p "$APP_HOME" WORKDIR "$APP_HOME" # COPY src/conf/ conf/ # COPY src/views/ views/ -COPY --from=builder "$APP_HOME"/${FOLDER_NAME}.out $APP_HOME -COPY --from=builder "$APP_HOME"/adserver $APP_HOME -COPY --from=builder "$APP_HOME"/eventserver $APP_HOME -COPY --from=builder "$APP_HOME"/panel $APP_HOME -COPY --from=builder "$APP_HOME"/publisherwebsite $APP_HOME - -EXPOSE 8083 -CMD ["./${FOLDER_NAME}.out"] +COPY --from=builder "$BUILDER_HOME"/"${FOLDER_NAME}"/output.out $APP_HOME +COPY --from=builder "$BUILDER_HOME"/"${FOLDER_NAME}"/.env $APP_HOME +COPY --from=builder "$BUILDER_HOME"/adserver /app/adserver +COPY --from=builder "$BUILDER_HOME"/eventserver /app/eventserver +COPY --from=builder "$BUILDER_HOME"/panel /app/panel +COPY --from=builder "$BUILDER_HOME"/publisherwebsite /app/publisherwebsite +COPY --from=builder "$BUILDER_HOME"/common /app/common + +EXPOSE $PORT_NUMBER + +# CMD ["/bin/bash"] +CMD ["./output.out"] +# CMD ["./${FOLDER_NAME}.out"] +# CMD ./${envFOLDER_NAME}.out +# CMD ["sh", "-c", "${envFOLDER_NAME}.out"] + diff --git a/docker-compose.yml b/docker-compose.yml index 7d0db4c..ac81ddb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: panel: build: @@ -7,6 +5,7 @@ services: dockerfile: Dockerfile args: - FOLDER_NAME=panel + - PORT_NUMBER=8083 ports: - "8083:8083" env_file: @@ -19,9 +18,9 @@ services: db: image: 'postgres:15.7-alpine' environment: - - 'POSTGRES_DB=?' - - 'POSTGRES_USER=?' - - 'POSTGRES_PASSWORD=?' + - 'POSTGRES_DB=mini_yektanet_db' + - 'POSTGRES_USER=postgres' + - 'POSTGRES_PASSWORD=1234' ports: - '5433:5432' restart: unless-stopped From 20e0f208fe880da51cb5d68f4ff1ae4e5b3562de Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 10:08:31 +0330 Subject: [PATCH 04/41] change running hostname gin to 0.0.0.0 --- adserver/main.go | 2 +- common/.env.example | 1 + eventserver/main.go | 2 +- panel/main.go | 2 +- publisherwebsite/main.go | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/adserver/main.go b/adserver/main.go index 8372eba..4bbfa68 100644 --- a/adserver/main.go +++ b/adserver/main.go @@ -35,5 +35,5 @@ func main() { if port == "" { port = "8081" } - r.Run(os.Getenv("AD_SERVER_HOSTNAME") + ":" + port) + r.Run(os.Getenv("GIN_HOSTNAME") + ":" + port) } diff --git a/common/.env.example b/common/.env.example index fd758f0..c636864 100644 --- a/common/.env.example +++ b/common/.env.example @@ -4,3 +4,4 @@ DB_USER=postgres DB_PASSWORD= DB_NAME=mini_yektanet_db PRIVATE_KEY= +GIN_HOSTNAME=0.0.0.0 \ No newline at end of file diff --git a/eventserver/main.go b/eventserver/main.go index 79361fa..72f2bf4 100644 --- a/eventserver/main.go +++ b/eventserver/main.go @@ -44,5 +44,5 @@ func main() { if port == "" { port = "8082" } - r.Run(os.Getenv("EVENT_SERVER_HOSTNAME") + ":" + port) + r.Run(os.Getenv("GIN_HOSTNAME") + ":" + port) } diff --git a/panel/main.go b/panel/main.go index 05dd5f7..8fbcba4 100644 --- a/panel/main.go +++ b/panel/main.go @@ -50,5 +50,5 @@ func main() { if port == "" { port = "8083" } - r.Run(os.Getenv("PANEL_HOSTNAME") + ":" + port) + r.Run(os.Getenv("GIN_HOSTNAME") + ":" + port) } diff --git a/publisherwebsite/main.go b/publisherwebsite/main.go index 4d5c2c7..78c4faa 100644 --- a/publisherwebsite/main.go +++ b/publisherwebsite/main.go @@ -37,7 +37,7 @@ func main() { if port == "" { port = "8084" } - r.Run(os.Getenv("PUBLISHER_WEBSITE_HOSTNAME") + ":" + port) + r.Run(os.Getenv("GIN_HOSTNAME") + ":" + port) } func getSite(c *gin.Context) { From 13a8e0f971a3145fe0746ad4e7d91fe4376c71de Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 10:14:45 +0330 Subject: [PATCH 05/41] add other services --- docker-compose.yml | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ac81ddb..a2c9325 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,13 +8,43 @@ services: - PORT_NUMBER=8083 ports: - "8083:8083" - env_file: - - ./panel/.env + # env_file: + # - ./panel/.env volumes: - "panel_static:/app/panel/static" depends_on: db: condition: service_healthy + publisherwebsite: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=publisherwebsite + - PORT_NUMBER=8084 + ports: + - "8084:8084" + volumes: + - "publisherwebsite_static:/app/publisherwebsite/static" + - "publisherwebsite_html:/app/publisherwebsite/html" + adserver: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=adserver + - PORT_NUMBER=8081 + ports: + - "8081:8081" + eventserver: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=eventserver + - PORT_NUMBER=8082 + ports: + - "8082:8082" db: image: 'postgres:15.7-alpine' environment: @@ -35,3 +65,5 @@ services: volumes: panel_static: postgres_data: + publisherwebsite_static: + publisherwebsite_html: From ea05ea62f69958f8bfb76ef53879b175693db84e Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 10:17:57 +0330 Subject: [PATCH 06/41] fix indention --- docker-compose.yml | 60 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a2c9325..28d16db 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,36 +15,36 @@ services: depends_on: db: condition: service_healthy - publisherwebsite: - build: - context: . - dockerfile: Dockerfile - args: - - FOLDER_NAME=publisherwebsite - - PORT_NUMBER=8084 - ports: - - "8084:8084" - volumes: - - "publisherwebsite_static:/app/publisherwebsite/static" - - "publisherwebsite_html:/app/publisherwebsite/html" - adserver: - build: - context: . - dockerfile: Dockerfile - args: - - FOLDER_NAME=adserver - - PORT_NUMBER=8081 - ports: - - "8081:8081" - eventserver: - build: - context: . - dockerfile: Dockerfile - args: - - FOLDER_NAME=eventserver - - PORT_NUMBER=8082 - ports: - - "8082:8082" + publisherwebsite: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=publisherwebsite + - PORT_NUMBER=8084 + ports: + - "8084:8084" + volumes: + - "publisherwebsite_static:/app/publisherwebsite/static" + - "publisherwebsite_html:/app/publisherwebsite/html" + adserver: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=adserver + - PORT_NUMBER=8081 + ports: + - "8081:8081" + eventserver: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=eventserver + - PORT_NUMBER=8082 + ports: + - "8082:8082" db: image: 'postgres:15.7-alpine' environment: From 02208b24f1274a069f59eb6d46be6afcc93e98dc Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 10:20:43 +0330 Subject: [PATCH 07/41] change indention From e338f43515a1778a5a51db6adfe7b417bef5d302 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sat, 27 Jul 2024 16:13:08 +0330 Subject: [PATCH 08/41] add initial files --- Dockerfile | 42 ++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 38 ++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1deb02f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM golang:1.22.4-bullseye as builder +# FROM registry.docker.ir/golang:1.22.4-alpine as builder + +ARG FOLDER_NAME +# ENV FOLDER_NAME=$FOLDER_NAME + +ENV APP_HOME /app/ + +WORKDIR "$APP_HOME" + +COPY go.mod ./ +RUN go mod download + + +COPY ${FOLDER_NAME} . +COPY common . +COPY adserver/.env adserver +COPY eventserver/.env eventserver +COPY panel/.env panel +COPY publisherwebsite/.env publisherwebsite + +RUN go mod verify +WORKDIR ${FOLDER_NAME} +RUN go build -o ${FOLDER_NAME}.out + +# FROM registry.docker.ir/golang:1.22.4-alpine +FROM golang:1.22.4-bullseye + +ENV APP_HOME /app/${FOLDER_NAME} +RUN mkdir -p "$APP_HOME" +WORKDIR "$APP_HOME" + +# COPY src/conf/ conf/ +# COPY src/views/ views/ +COPY --from=builder "$APP_HOME"/${FOLDER_NAME}.out $APP_HOME +COPY --from=builder "$APP_HOME"/adserver $APP_HOME +COPY --from=builder "$APP_HOME"/eventserver $APP_HOME +COPY --from=builder "$APP_HOME"/panel $APP_HOME +COPY --from=builder "$APP_HOME"/publisherwebsite $APP_HOME + +EXPOSE 8083 +CMD ["./${FOLDER_NAME}.out"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7d0db4c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.8' + +services: + panel: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=panel + ports: + - "8083:8083" + env_file: + - ./panel/.env + volumes: + - "panel_static:/app/panel/static" + depends_on: + db: + condition: service_healthy + db: + image: 'postgres:15.7-alpine' + environment: + - 'POSTGRES_DB=?' + - 'POSTGRES_USER=?' + - 'POSTGRES_PASSWORD=?' + ports: + - '5433:5432' + restart: unless-stopped + volumes: + - "postgres_data:/var/lib/postgresql/data" + healthcheck: + test: [ "CMD-SHELL", "pg_isready", "-d", "db_prod" ] + interval: 30s + timeout: 60s + retries: 5 + start_period: 80s +volumes: + panel_static: + postgres_data: diff --git a/go.mod b/go.mod index fbaeb49..0d99bfd 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module YellowBloomKnapsack/mini-yektanet go 1.22.4 require ( - github.com/beevik/guid v1.0.0 + // github.com/beevik/guid v1.0.0 github.com/gin-contrib/cors v1.7.2 github.com/gin-gonic/gin v1.10.0 github.com/joho/godotenv v1.5.1 From 38681de5d55b43e5391759ce0cc9b104a2cb3220 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sat, 27 Jul 2024 17:03:29 +0330 Subject: [PATCH 09/41] add arg for second stage --- Dockerfile | 2 +- copyenvs.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100755 copyenvs.sh diff --git a/Dockerfile b/Dockerfile index 1deb02f..7201f56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN go build -o ${FOLDER_NAME}.out # FROM registry.docker.ir/golang:1.22.4-alpine FROM golang:1.22.4-bullseye - +ARG FOLDER_NAME ENV APP_HOME /app/${FOLDER_NAME} RUN mkdir -p "$APP_HOME" WORKDIR "$APP_HOME" diff --git a/copyenvs.sh b/copyenvs.sh new file mode 100755 index 0000000..8c07a14 --- /dev/null +++ b/copyenvs.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +scp -P 2233 panel/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/panel/.env +scp -P 2233 adserver/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/adserver/.env +scp -P 2233 common/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/common/.env +scp -P 2233 eventserver/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/eventserver/.env +scp -P 2233 publisherwebsite/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/publisherwebsite/.env \ No newline at end of file From d7226a16740400342a30a3596eab00aa99af0ac3 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sat, 27 Jul 2024 19:02:45 +0330 Subject: [PATCH 10/41] add docker and docker-compose --- Dockerfile | 48 +++++++++++++++++++++++++++++----------------- docker-compose.yml | 9 ++++----- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7201f56..e60f826 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,41 +2,53 @@ FROM golang:1.22.4-bullseye as builder # FROM registry.docker.ir/golang:1.22.4-alpine as builder ARG FOLDER_NAME +ARG PORT_NUMBER # ENV FOLDER_NAME=$FOLDER_NAME +ENV BUILDER_HOME /app/ -ENV APP_HOME /app/ - -WORKDIR "$APP_HOME" +WORKDIR "$BUILDER_HOME" COPY go.mod ./ RUN go mod download -COPY ${FOLDER_NAME} . -COPY common . -COPY adserver/.env adserver -COPY eventserver/.env eventserver -COPY panel/.env panel -COPY publisherwebsite/.env publisherwebsite +COPY ${FOLDER_NAME} ./${FOLDER_NAME} +COPY common ./common +COPY adserver/.env adserver/.env +COPY eventserver/.env eventserver/.env +COPY panel/.env panel/.env +COPY publisherwebsite/.env publisherwebsite/.env +COPY go.sum ./ RUN go mod verify WORKDIR ${FOLDER_NAME} -RUN go build -o ${FOLDER_NAME}.out +RUN go build -o output.out # FROM registry.docker.ir/golang:1.22.4-alpine FROM golang:1.22.4-bullseye ARG FOLDER_NAME +ENV envFOLDER_NAME=$FOLDER_NAME +RUN mkdir -p /app ENV APP_HOME /app/${FOLDER_NAME} +ENV BUILDER_HOME /app/ RUN mkdir -p "$APP_HOME" WORKDIR "$APP_HOME" # COPY src/conf/ conf/ # COPY src/views/ views/ -COPY --from=builder "$APP_HOME"/${FOLDER_NAME}.out $APP_HOME -COPY --from=builder "$APP_HOME"/adserver $APP_HOME -COPY --from=builder "$APP_HOME"/eventserver $APP_HOME -COPY --from=builder "$APP_HOME"/panel $APP_HOME -COPY --from=builder "$APP_HOME"/publisherwebsite $APP_HOME - -EXPOSE 8083 -CMD ["./${FOLDER_NAME}.out"] +COPY --from=builder "$BUILDER_HOME"/"${FOLDER_NAME}"/output.out $APP_HOME +COPY --from=builder "$BUILDER_HOME"/"${FOLDER_NAME}"/.env $APP_HOME +COPY --from=builder "$BUILDER_HOME"/adserver /app/adserver +COPY --from=builder "$BUILDER_HOME"/eventserver /app/eventserver +COPY --from=builder "$BUILDER_HOME"/panel /app/panel +COPY --from=builder "$BUILDER_HOME"/publisherwebsite /app/publisherwebsite +COPY --from=builder "$BUILDER_HOME"/common /app/common + +EXPOSE $PORT_NUMBER + +# CMD ["/bin/bash"] +CMD ["./output.out"] +# CMD ["./${FOLDER_NAME}.out"] +# CMD ./${envFOLDER_NAME}.out +# CMD ["sh", "-c", "${envFOLDER_NAME}.out"] + diff --git a/docker-compose.yml b/docker-compose.yml index 7d0db4c..ac81ddb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: panel: build: @@ -7,6 +5,7 @@ services: dockerfile: Dockerfile args: - FOLDER_NAME=panel + - PORT_NUMBER=8083 ports: - "8083:8083" env_file: @@ -19,9 +18,9 @@ services: db: image: 'postgres:15.7-alpine' environment: - - 'POSTGRES_DB=?' - - 'POSTGRES_USER=?' - - 'POSTGRES_PASSWORD=?' + - 'POSTGRES_DB=mini_yektanet_db' + - 'POSTGRES_USER=postgres' + - 'POSTGRES_PASSWORD=1234' ports: - '5433:5432' restart: unless-stopped From e0765963b80a9bf38e78b538d249243ece0843dc Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 10:08:31 +0330 Subject: [PATCH 11/41] change running hostname gin to 0.0.0.0 --- adserver/main.go | 2 +- common/.env.example | 1 + eventserver/main.go | 2 +- panel/main.go | 2 +- publisherwebsite/main.go | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/adserver/main.go b/adserver/main.go index 6a221c0..38b2887 100644 --- a/adserver/main.go +++ b/adserver/main.go @@ -41,5 +41,5 @@ func main() { if port == "" { port = "8081" } - r.Run(os.Getenv("AD_SERVER_HOSTNAME") + ":" + port) + r.Run(os.Getenv("GIN_HOSTNAME") + ":" + port) } diff --git a/common/.env.example b/common/.env.example index fd758f0..c636864 100644 --- a/common/.env.example +++ b/common/.env.example @@ -4,3 +4,4 @@ DB_USER=postgres DB_PASSWORD= DB_NAME=mini_yektanet_db PRIVATE_KEY= +GIN_HOSTNAME=0.0.0.0 \ No newline at end of file diff --git a/eventserver/main.go b/eventserver/main.go index ebf9124..c9144c6 100644 --- a/eventserver/main.go +++ b/eventserver/main.go @@ -53,5 +53,5 @@ func main() { if port == "" { port = "8082" } - r.Run(os.Getenv("EVENT_SERVER_HOSTNAME") + ":" + port) + r.Run(os.Getenv("GIN_HOSTNAME") + ":" + port) } diff --git a/panel/main.go b/panel/main.go index 05dd5f7..8fbcba4 100644 --- a/panel/main.go +++ b/panel/main.go @@ -50,5 +50,5 @@ func main() { if port == "" { port = "8083" } - r.Run(os.Getenv("PANEL_HOSTNAME") + ":" + port) + r.Run(os.Getenv("GIN_HOSTNAME") + ":" + port) } diff --git a/publisherwebsite/main.go b/publisherwebsite/main.go index 4d5c2c7..78c4faa 100644 --- a/publisherwebsite/main.go +++ b/publisherwebsite/main.go @@ -37,7 +37,7 @@ func main() { if port == "" { port = "8084" } - r.Run(os.Getenv("PUBLISHER_WEBSITE_HOSTNAME") + ":" + port) + r.Run(os.Getenv("GIN_HOSTNAME") + ":" + port) } func getSite(c *gin.Context) { From 1abaa1ecf57037c1f086de2087c22d7f046f8b50 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 10:14:45 +0330 Subject: [PATCH 12/41] add other services --- docker-compose.yml | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ac81ddb..a2c9325 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,13 +8,43 @@ services: - PORT_NUMBER=8083 ports: - "8083:8083" - env_file: - - ./panel/.env + # env_file: + # - ./panel/.env volumes: - "panel_static:/app/panel/static" depends_on: db: condition: service_healthy + publisherwebsite: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=publisherwebsite + - PORT_NUMBER=8084 + ports: + - "8084:8084" + volumes: + - "publisherwebsite_static:/app/publisherwebsite/static" + - "publisherwebsite_html:/app/publisherwebsite/html" + adserver: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=adserver + - PORT_NUMBER=8081 + ports: + - "8081:8081" + eventserver: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=eventserver + - PORT_NUMBER=8082 + ports: + - "8082:8082" db: image: 'postgres:15.7-alpine' environment: @@ -35,3 +65,5 @@ services: volumes: panel_static: postgres_data: + publisherwebsite_static: + publisherwebsite_html: From 935d1db24f068417f9eff151e4c2b52cac3aa004 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 10:17:57 +0330 Subject: [PATCH 13/41] fix indention --- docker-compose.yml | 60 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a2c9325..28d16db 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,36 +15,36 @@ services: depends_on: db: condition: service_healthy - publisherwebsite: - build: - context: . - dockerfile: Dockerfile - args: - - FOLDER_NAME=publisherwebsite - - PORT_NUMBER=8084 - ports: - - "8084:8084" - volumes: - - "publisherwebsite_static:/app/publisherwebsite/static" - - "publisherwebsite_html:/app/publisherwebsite/html" - adserver: - build: - context: . - dockerfile: Dockerfile - args: - - FOLDER_NAME=adserver - - PORT_NUMBER=8081 - ports: - - "8081:8081" - eventserver: - build: - context: . - dockerfile: Dockerfile - args: - - FOLDER_NAME=eventserver - - PORT_NUMBER=8082 - ports: - - "8082:8082" + publisherwebsite: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=publisherwebsite + - PORT_NUMBER=8084 + ports: + - "8084:8084" + volumes: + - "publisherwebsite_static:/app/publisherwebsite/static" + - "publisherwebsite_html:/app/publisherwebsite/html" + adserver: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=adserver + - PORT_NUMBER=8081 + ports: + - "8081:8081" + eventserver: + build: + context: . + dockerfile: Dockerfile + args: + - FOLDER_NAME=eventserver + - PORT_NUMBER=8082 + ports: + - "8082:8082" db: image: 'postgres:15.7-alpine' environment: From aa8cbf68dbe4dae43f96ac83aa0cc5632f9094f2 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 10:20:43 +0330 Subject: [PATCH 14/41] change indention From f89c5e1725d19544d23ff17094025da52d471881 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 13:00:35 +0330 Subject: [PATCH 15/41] add kafka and redis --- .gitignore | 2 ++ Dockerfile | 9 +++--- copyenvs.sh | 25 ++++++++++++--- docker-compose.yml | 79 ++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 102 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index fba152a..00d27d7 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ .idea **/test*.db + +**/*.private.sh diff --git a/Dockerfile b/Dockerfile index e60f826..39ddd39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,8 +9,9 @@ ENV BUILDER_HOME /app/ WORKDIR "$BUILDER_HOME" COPY go.mod ./ +COPY go.sum ./ RUN go mod download - +RUN go mod verify COPY ${FOLDER_NAME} ./${FOLDER_NAME} COPY common ./common @@ -19,13 +20,11 @@ COPY eventserver/.env eventserver/.env COPY panel/.env panel/.env COPY publisherwebsite/.env publisherwebsite/.env -COPY go.sum ./ -RUN go mod verify WORKDIR ${FOLDER_NAME} -RUN go build -o output.out +RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o output.out # FROM registry.docker.ir/golang:1.22.4-alpine -FROM golang:1.22.4-bullseye +FROM alpine:3.20.2 ARG FOLDER_NAME ENV envFOLDER_NAME=$FOLDER_NAME RUN mkdir -p /app diff --git a/copyenvs.sh b/copyenvs.sh index 8c07a14..6b4245a 100755 --- a/copyenvs.sh +++ b/copyenvs.sh @@ -1,6 +1,21 @@ #!/usr/bin/env bash -scp -P 2233 panel/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/panel/.env -scp -P 2233 adserver/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/adserver/.env -scp -P 2233 common/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/common/.env -scp -P 2233 eventserver/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/eventserver/.env -scp -P 2233 publisherwebsite/.env comp2@95.217.125.138:/home/comp2/mini-yektanet/publisherwebsite/.env \ No newline at end of file + +# Declare variables +SERVER_USER= +SERVER_IP= +SERVER_PORT= +REMOTE_DIR="/home/$SERVER_USER/mini-yektanet" + +# Function to perform SCP +perform_scp() { + local source_file="$1" + local dest_path="$2" + scp -P $SERVER_PORT "$source_file" "$SERVER_USER@$SERVER_IP:$dest_path" +} + +# Perform SCP for each .env file +perform_scp "panel/.env" "$REMOTE_DIR/panel/.env" +perform_scp "adserver/.env" "$REMOTE_DIR/adserver/.env" +perform_scp "common/.env" "$REMOTE_DIR/common/.env" +perform_scp "eventserver/.env" "$REMOTE_DIR/eventserver/.env" +perform_scp "publisherwebsite/.env" "$REMOTE_DIR/publisherwebsite/.env" diff --git a/docker-compose.yml b/docker-compose.yml index 28d16db..8a657a7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: args: - FOLDER_NAME=panel - PORT_NUMBER=8083 + restart: unless-stopped ports: - "8083:8083" # env_file: @@ -22,11 +23,12 @@ services: args: - FOLDER_NAME=publisherwebsite - PORT_NUMBER=8084 + restart: unless-stopped ports: - "8084:8084" volumes: - "publisherwebsite_static:/app/publisherwebsite/static" - - "publisherwebsite_html:/app/publisherwebsite/html" + # - "publisherwebsite_html:/app/publisherwebsite/html" adserver: build: context: . @@ -34,8 +36,11 @@ services: args: - FOLDER_NAME=adserver - PORT_NUMBER=8081 + restart: unless-stopped ports: - "8081:8081" + depends_on: + - kafka eventserver: build: context: . @@ -43,8 +48,11 @@ services: args: - FOLDER_NAME=eventserver - PORT_NUMBER=8082 + restart: unless-stopped ports: - "8082:8082" + depends_on: + - kafka db: image: 'postgres:15.7-alpine' environment: @@ -62,8 +70,73 @@ services: timeout: 60s retries: 5 start_period: 80s + redis: + image: redis:7.2.5-alpine + ports: + - "6379:6379" + volumes: + - redis-data:/data + command: redis-server --appendonly yes --loadmodule /opt/redis-stack/lib/redisbloom.so + restart: unless-stopped + healthcheck: + test: [ "CMD", "redis-cli", "ping" ] + interval: 10s + timeout: 5s + retries: 3 + start_period: 30s + zookeeper: + image: zookeeper:3.8.4 + environment: + ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_TICK_TIME: 2000 + restart: unless-stopped + ports: + - 2181:2181 + volumes: + # - zookeeper-data:/var/lib/zookeeper/data + - zookeeper-data:/data + # - zookeeper-logs:/var/lib/zookeeper/log + - zookeeper-logs:/log + healthcheck: + test: nc -z localhost 2181 || exit -1 + interval: 10s + timeout: 5s + retries: 3 + kafka: + image: apache/kafka:3.7.1 + # container_name: kafka + depends_on: + - zookeeper + ports: + - 9092:9092 + restart: unless-stopped + environment: + KAFKA_BROKER_ID: 1 + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + # KAFKA_LISTENERS: PLAINTEXT://:9092 + # KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092 + KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:9092 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT + KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 + # KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 + # KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 + KAFKA_CREATE_TOPICS: "click_events:1:1,impression_events:1:1" + volumes: + # - kafka-data:/var/lib/kafka/data + - ./kafka-data:/opt/kafka/data + healthcheck: + test: kafka-topics --bootstrap-server kafka:9092 --list + interval: 30s + timeout: 10s + retries: 3 + volumes: panel_static: postgres_data: - publisherwebsite_static: - publisherwebsite_html: + publisherwebsite_static: # publisherwebsite_html: + + redis-data: + zookeeper-data: + zookeeper-logs: + kafka-data: From a98bb451365c0fe9c2de8bf088bca92e76b46f74 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 13:22:04 +0330 Subject: [PATCH 16/41] edit topic partition --- docker-compose.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8a657a7..62b3178 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,7 +40,8 @@ services: ports: - "8081:8081" depends_on: - - kafka + - kafka: + condition: service_healthy eventserver: build: context: . @@ -52,7 +53,8 @@ services: ports: - "8082:8082" depends_on: - - kafka + - kafka: + condition: service_healthy db: image: 'postgres:15.7-alpine' environment: @@ -106,7 +108,8 @@ services: image: apache/kafka:3.7.1 # container_name: kafka depends_on: - - zookeeper + - zookeeper: + condition: service_healthy ports: - 9092:9092 restart: unless-stopped @@ -118,10 +121,10 @@ services: KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:9092 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 + # KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 # KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 # KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 - KAFKA_CREATE_TOPICS: "click_events:1:1,impression_events:1:1" + KAFKA_CREATE_TOPICS: "click_events:3:1,impression_events:3:1" volumes: # - kafka-data:/var/lib/kafka/data - ./kafka-data:/opt/kafka/data From d8d89551eb95f73da7de21fbb48b2a905d3a6a13 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 13:43:09 +0330 Subject: [PATCH 17/41] fix dependablity of services --- docker-compose.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 62b3178..d4ea988 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,8 +40,10 @@ services: ports: - "8081:8081" depends_on: - - kafka: + kafka: condition: service_healthy + panel: + condition: service_started eventserver: build: context: . @@ -53,7 +55,7 @@ services: ports: - "8082:8082" depends_on: - - kafka: + kafka: condition: service_healthy db: image: 'postgres:15.7-alpine' @@ -108,7 +110,7 @@ services: image: apache/kafka:3.7.1 # container_name: kafka depends_on: - - zookeeper: + zookeeper: condition: service_healthy ports: - 9092:9092 From 2b93cc98750d3707c20aa6a0c74d55732f7a8151 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 13:47:32 +0330 Subject: [PATCH 18/41] change back to default build command --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 39ddd39..0c58504 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,8 @@ COPY panel/.env panel/.env COPY publisherwebsite/.env publisherwebsite/.env WORKDIR ${FOLDER_NAME} -RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o output.out +# RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o output.out +RUN go build -o output.out # FROM registry.docker.ir/golang:1.22.4-alpine FROM alpine:3.20.2 From 74b4eb9fe3b47414c42a33bc55732ec110cc1dd8 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 14:27:45 +0330 Subject: [PATCH 19/41] change kafka envs --- docker-compose.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index d4ea988..80a0f8d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -113,6 +113,7 @@ services: zookeeper: condition: service_healthy ports: + - 29092:29092 - 9092:9092 restart: unless-stopped environment: @@ -120,13 +121,15 @@ services: KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 # KAFKA_LISTENERS: PLAINTEXT://:9092 # KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092 - KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:9092 + # KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:9092 + KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT # KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 # KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 # KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 KAFKA_CREATE_TOPICS: "click_events:3:1,impression_events:3:1" + volumes: # - kafka-data:/var/lib/kafka/data - ./kafka-data:/opt/kafka/data From 372d4023c171d342695c0800065143cbc80681a5 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 14:30:56 +0330 Subject: [PATCH 20/41] fix health check kafka --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 80a0f8d..6f80704 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -134,7 +134,7 @@ services: # - kafka-data:/var/lib/kafka/data - ./kafka-data:/opt/kafka/data healthcheck: - test: kafka-topics --bootstrap-server kafka:9092 --list + test: kafka-topics --bootstrap-server localhost:9092 --list interval: 30s timeout: 10s retries: 3 From ced23065295deaffe195fd15b5e61cff35ee7823 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 14:46:24 +0330 Subject: [PATCH 21/41] remove health check kafka for test --- docker-compose.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6f80704..31ea51b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,7 +41,7 @@ services: - "8081:8081" depends_on: kafka: - condition: service_healthy + condition: service_started panel: condition: service_started eventserver: @@ -56,7 +56,7 @@ services: - "8082:8082" depends_on: kafka: - condition: service_healthy + condition: service_started db: image: 'postgres:15.7-alpine' environment: @@ -133,11 +133,11 @@ services: volumes: # - kafka-data:/var/lib/kafka/data - ./kafka-data:/opt/kafka/data - healthcheck: - test: kafka-topics --bootstrap-server localhost:9092 --list - interval: 30s - timeout: 10s - retries: 3 + # healthcheck: + # test: kafka-topics --bootstrap-server kafka:9092 --list + # interval: 30s + # timeout: 10s + # retries: 3 volumes: panel_static: From 3ca17bb1e7777c7bcba1208d5c24a741d2d61244 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 14:48:29 +0330 Subject: [PATCH 22/41] remove restart flag for test --- docker-compose.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 31ea51b..774e6a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: args: - FOLDER_NAME=panel - PORT_NUMBER=8083 - restart: unless-stopped + #restart: unless-stopped ports: - "8083:8083" # env_file: @@ -23,7 +23,7 @@ services: args: - FOLDER_NAME=publisherwebsite - PORT_NUMBER=8084 - restart: unless-stopped + #restart: unless-stopped ports: - "8084:8084" volumes: @@ -36,7 +36,7 @@ services: args: - FOLDER_NAME=adserver - PORT_NUMBER=8081 - restart: unless-stopped + #restart: unless-stopped ports: - "8081:8081" depends_on: @@ -51,7 +51,7 @@ services: args: - FOLDER_NAME=eventserver - PORT_NUMBER=8082 - restart: unless-stopped + #restart: unless-stopped ports: - "8082:8082" depends_on: @@ -65,7 +65,7 @@ services: - 'POSTGRES_PASSWORD=1234' ports: - '5433:5432' - restart: unless-stopped + #restart: unless-stopped volumes: - "postgres_data:/var/lib/postgresql/data" healthcheck: @@ -81,7 +81,7 @@ services: volumes: - redis-data:/data command: redis-server --appendonly yes --loadmodule /opt/redis-stack/lib/redisbloom.so - restart: unless-stopped + #restart: unless-stopped healthcheck: test: [ "CMD", "redis-cli", "ping" ] interval: 10s @@ -93,7 +93,7 @@ services: environment: ZOOKEEPER_CLIENT_PORT: 2181 ZOOKEEPER_TICK_TIME: 2000 - restart: unless-stopped + #restart: unless-stopped ports: - 2181:2181 volumes: @@ -115,7 +115,7 @@ services: ports: - 29092:29092 - 9092:9092 - restart: unless-stopped + #restart: unless-stopped environment: KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 From 4819ba4cd5331045552cefd868d03a2dee100ef1 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 14:54:43 +0330 Subject: [PATCH 23/41] change runner back to golang --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0c58504..2b2d49f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,8 @@ WORKDIR ${FOLDER_NAME} RUN go build -o output.out # FROM registry.docker.ir/golang:1.22.4-alpine -FROM alpine:3.20.2 +# FROM alpine:3.20.2 +FROM golang:1.22.4-bullseye ARG FOLDER_NAME ENV envFOLDER_NAME=$FOLDER_NAME RUN mkdir -p /app From 6d8f41212926c19a338364ad9ebb9cd6c3580d24 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 15:09:06 +0330 Subject: [PATCH 24/41] fix redis bloom filter --- Dockerfile.redis | 7 +++++++ docker-compose.yml | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 Dockerfile.redis diff --git a/Dockerfile.redis b/Dockerfile.redis new file mode 100644 index 0000000..280d354 --- /dev/null +++ b/Dockerfile.redis @@ -0,0 +1,7 @@ +FROM redislabs/rebloom:2.8.1 as builder + +FROM redis:7.2.5-alpine +COPY --from=builder /usr/lib/redis/modules/redisbloom.so /usr/lib/redis/modules/redisbloom.so + +# CMD ["/run.sh", "--loadmodule", "/usr/lib/redis/modules/redisbloom.so"] +CMD ["redis-server", "--appendonly", "yes", "--loadmodule", "/usr/lib/redis/modules/redisbloom.so"] diff --git a/docker-compose.yml b/docker-compose.yml index 774e6a3..f67d1c3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -75,12 +75,15 @@ services: retries: 5 start_period: 80s redis: - image: redis:7.2.5-alpine + # image: redis:7.2.5-alpine + build: + context: . + dockerfile: Dockerfile.redis ports: - "6379:6379" volumes: - redis-data:/data - command: redis-server --appendonly yes --loadmodule /opt/redis-stack/lib/redisbloom.so + # command: redis-server --appendonly yes --loadmodule /opt/redis-stack/lib/redisbloom.so #restart: unless-stopped healthcheck: test: [ "CMD", "redis-cli", "ping" ] From c92fe462499dbfd301f9df9b60f03cd03e61a6e2 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 15:43:08 +0330 Subject: [PATCH 25/41] fix kafka --- docker-compose.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f67d1c3..a2cdefa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -92,7 +92,8 @@ services: retries: 3 start_period: 30s zookeeper: - image: zookeeper:3.8.4 + # image: zookeeper:3.8.4 + image: confluentinc/cp-zookeeper:7.5.0 environment: ZOOKEEPER_CLIENT_PORT: 2181 ZOOKEEPER_TICK_TIME: 2000 @@ -110,7 +111,8 @@ services: timeout: 5s retries: 3 kafka: - image: apache/kafka:3.7.1 + # image: apache/kafka:3.7.1 + image: confluentinc/cp-server:7.5.0 # container_name: kafka depends_on: zookeeper: @@ -125,17 +127,25 @@ services: # KAFKA_LISTENERS: PLAINTEXT://:9092 # KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092 # KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:9092 + # KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092 + # KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 + # KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT + # KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 + + command: sh -c "((sleep 15 && kafka-topics --create --if-not-exists --zookeeper zookeeper:2181 --replication-factor 1 --partitions 3 --topic click_events && kafka-topics --create --if-not-exists --zookeeper zookeeper:2181 --replication-factor 1 --partitions 3 --topic impression_events)&) && /etc/confluent/docker/run "> # KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 # KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 # KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 - KAFKA_CREATE_TOPICS: "click_events:3:1,impression_events:3:1" + # KAFKA_CREATE_TOPICS: "click_events:3:1,impression_events:3:1" volumes: # - kafka-data:/var/lib/kafka/data - - ./kafka-data:/opt/kafka/data + - kafka-data:/opt/kafka/data + - kafka-docker-sock:/var/run/docker.sock # healthcheck: # test: kafka-topics --bootstrap-server kafka:9092 --list # interval: 30s @@ -146,8 +156,8 @@ volumes: panel_static: postgres_data: publisherwebsite_static: # publisherwebsite_html: - redis-data: zookeeper-data: zookeeper-logs: kafka-data: + kafka-docker-sock: From 45bfe23ee4cd8bdbe2cba49800a56afa028713d4 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 15:59:20 +0330 Subject: [PATCH 26/41] init topics kafka --- docker-compose.yml | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a2cdefa..6ea9f83 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -112,7 +112,7 @@ services: retries: 3 kafka: # image: apache/kafka:3.7.1 - image: confluentinc/cp-server:7.5.0 + image: &kafka-image confluentinc/cp-server:7.5.0 # container_name: kafka depends_on: zookeeper: @@ -135,8 +135,7 @@ services: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 - - command: sh -c "((sleep 15 && kafka-topics --create --if-not-exists --zookeeper zookeeper:2181 --replication-factor 1 --partitions 3 --topic click_events && kafka-topics --create --if-not-exists --zookeeper zookeeper:2181 --replication-factor 1 --partitions 3 --topic impression_events)&) && /etc/confluent/docker/run "> + # command: sh -c "((sleep 15 && kafka-topics --create --if-not-exists --zookeeper zookeeper:2181 --replication-factor 1 --partitions 3 --topic click_events && kafka-topics --create --if-not-exists --zookeeper zookeeper:2181 --replication-factor 1 --partitions 3 --topic impression_events)&) && /etc/confluent/docker/run "> # KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 # KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 # KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 @@ -146,11 +145,21 @@ services: # - kafka-data:/var/lib/kafka/data - kafka-data:/opt/kafka/data - kafka-docker-sock:/var/run/docker.sock - # healthcheck: - # test: kafka-topics --bootstrap-server kafka:9092 --list - # interval: 30s - # timeout: 10s - # retries: 3 + healthcheck: + test: kafka-topics --bootstrap-server kafka:9092 --list + interval: 30s + timeout: 10s + retries: 3 + init-kafka: + image: *kafka-image + working_dir: /opt/bitnami/kafka/bin + entrypoint: /bin/bash + depends_on: + kafka: + condition: service_healthy + command: | + kafka-topics.sh --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 && + kafka-topics.sh --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 volumes: panel_static: From e1965468497b1a2e72de85e9774b5bafb66219a3 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 16:48:43 +0330 Subject: [PATCH 27/41] fix adserver public ip --- adserver/.env.example | 1 + docker-compose.yml | 7 +++---- panel/handlers/publisherhandler.go | 2 +- publisherwebsite/static/js/script.js | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/adserver/.env.example b/adserver/.env.example index 1dc12d7..40c1424 100644 --- a/adserver/.env.example +++ b/adserver/.env.example @@ -5,3 +5,4 @@ ADS_FETCH_INTERVAL_SECS=5 NOTIFY_API_PATH="/brake" BRAKE_DURATION_SECS=10 AD_SERVER_HOSTNAME=localhost +AD_SERVER_PUBLIC_HOSTNAME=localhost \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 6ea9f83..bd028af 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -152,14 +152,13 @@ services: retries: 3 init-kafka: image: *kafka-image - working_dir: /opt/bitnami/kafka/bin + # working_dir: /opt/bitnami/kafka/bin entrypoint: /bin/bash depends_on: kafka: condition: service_healthy - command: | - kafka-topics.sh --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 && - kafka-topics.sh --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 + command: > + bash -c "kafka-topics --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 && kafka-topics --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092" volumes: panel_static: diff --git a/panel/handlers/publisherhandler.go b/panel/handlers/publisherhandler.go index 2fe940c..2d831b9 100644 --- a/panel/handlers/publisherhandler.go +++ b/panel/handlers/publisherhandler.go @@ -163,6 +163,6 @@ func generateScript(publisherName string) string { if err != nil { return "error generating the script" } - adServerAPILink := "http://" + os.Getenv("AD_SERVER_HOSTNAME") + ":" + os.Getenv("AD_SERVER_PORT") + adServerAPILink := "http://" + os.Getenv("AD_SERVER_PUBLIC_HOSTNAME") + ":" + os.Getenv("AD_SERVER_PORT") return fmt.Sprintf(string(content), publisherName, adServerAPILink) } diff --git a/publisherwebsite/static/js/script.js b/publisherwebsite/static/js/script.js index baac982..7bc6d5e 100644 --- a/publisherwebsite/static/js/script.js +++ b/publisherwebsite/static/js/script.js @@ -14,7 +14,8 @@ JSON data received from AdServer must have the following fields: // const AdServerAPILink = %AdServerAPILink% const arr = window.location.href.split('/') const publisherName = arr[arr.length-1] -const AdServerAPILink = "http://localhost:8081" +// const AdServerAPILink = "http://localhost:8081" +const AdServerAPILink = arr[arr.length-2].replace("8084","8081") fetch(AdServerAPILink+"/"+publisherName) .then((res) => { From 65cbf67df47307cbf8a8d0c6bbad0abddf0eb94a Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 17:02:10 +0330 Subject: [PATCH 28/41] fix script fetch address --- publisherwebsite/static/js/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publisherwebsite/static/js/script.js b/publisherwebsite/static/js/script.js index 7bc6d5e..4d3260e 100644 --- a/publisherwebsite/static/js/script.js +++ b/publisherwebsite/static/js/script.js @@ -15,7 +15,7 @@ JSON data received from AdServer must have the following fields: const arr = window.location.href.split('/') const publisherName = arr[arr.length-1] // const AdServerAPILink = "http://localhost:8081" -const AdServerAPILink = arr[arr.length-2].replace("8084","8081") +const AdServerAPILink = "http://"+arr[arr.length-2].replace("8084","8081") fetch(AdServerAPILink+"/"+publisherName) .then((res) => { From d00eab266fd7eb1bb28a907445697084b0ba3fd4 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 17:14:01 +0330 Subject: [PATCH 29/41] fix address for static file for main server --- docker-compose.yml | 9 +++++---- panel/.env.example | 1 + panel/handlers/adhandler.go | 2 +- panel/handlers/adhandler_test.go | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bd028af..2fdc83a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,7 +41,7 @@ services: - "8081:8081" depends_on: kafka: - condition: service_started + condition: service_healthy panel: condition: service_started eventserver: @@ -56,7 +56,7 @@ services: - "8082:8082" depends_on: kafka: - condition: service_started + condition: service_healthy db: image: 'postgres:15.7-alpine' environment: @@ -157,8 +157,9 @@ services: depends_on: kafka: condition: service_healthy - command: > - bash -c "kafka-topics --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 && kafka-topics --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092" + command: | + kafka-topics --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 + kafka-topics --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 volumes: panel_static: diff --git a/panel/.env.example b/panel/.env.example index cd7dac6..6a512e0 100644 --- a/panel/.env.example +++ b/panel/.env.example @@ -7,3 +7,4 @@ SCRIPT_TEMPLATE_LOCATION="asset/scriptTemplate.js" TEST_DB_PATH="asset/test.db" AD_COST_CHECK_DURSTION_SECS=60 PANEL_HOSTNAME=localhost +PANEL_PUBLIC_HOSTNAME=localhost diff --git a/panel/handlers/adhandler.go b/panel/handlers/adhandler.go index a760ad2..18e63f4 100644 --- a/panel/handlers/adhandler.go +++ b/panel/handlers/adhandler.go @@ -27,7 +27,7 @@ func GetActiveAds(c *gin.Context) { adDTO := dto.AdDTO{ ID: ad.ID, Text: ad.Text, - ImagePath: "http://" + os.Getenv("PANEL_HOSTNAME") + ":" + os.Getenv("PANEL_PORT") + ad.ImagePath, + ImagePath: "http://" + os.Getenv("PANEL_PUBLIC_HOSTNAME") + ":" + os.Getenv("PANEL_PORT") + ad.ImagePath, Bid: ad.Bid, Website: ad.Website, TotalCost: ad.TotalCost, diff --git a/panel/handlers/adhandler_test.go b/panel/handlers/adhandler_test.go index 1f2550d..499ee15 100644 --- a/panel/handlers/adhandler_test.go +++ b/panel/handlers/adhandler_test.go @@ -82,7 +82,7 @@ func TestGetActiveAdsSuccessGetAllAds(t *testing.T) { adDTO := dto.AdDTO{ ID: ad.ID, Text: ad.Text, - ImagePath: "http://" + os.Getenv("PANEL_HOSTNAME") + ":" + os.Getenv("PANEL_PORT") + ad.ImagePath, + ImagePath: "http://" + os.Getenv("PANEL_PUBLIC_HOSTNAME") + ":" + os.Getenv("PANEL_PORT") + ad.ImagePath, Bid: ad.Bid, Website: ad.Website, } From 231f916993c893057ec7a95f0fe4659850a7de9d Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 17:27:43 +0330 Subject: [PATCH 30/41] fix public ip for event server --- adserver/handlers/handlers.go | 2 +- adserver/handlers/handlers_test.go | 2 +- eventserver/.env.example | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/adserver/handlers/handlers.go b/adserver/handlers/handlers.go index 07b7507..36c4ead 100644 --- a/adserver/handlers/handlers.go +++ b/adserver/handlers/handlers.go @@ -35,7 +35,7 @@ func (h *AdServerHandler) GetAd(c *gin.Context) { } eventServerPort := os.Getenv("EVENT_SERVER_PORT") - hostName := os.Getenv("EVENT_SERVER_HOSTNAME") + hostName := os.Getenv("EVENT_SERVER_PUBLIC_HOSTNAME") eventServerURL := "http://" + hostName + ":" + eventServerPort clickReqPath := os.Getenv("CLICK_REQ_PATH") diff --git a/adserver/handlers/handlers_test.go b/adserver/handlers/handlers_test.go index b64305c..807d319 100644 --- a/adserver/handlers/handlers_test.go +++ b/adserver/handlers/handlers_test.go @@ -46,7 +46,7 @@ func (m *MockTokenHandler) VerifyToken(encryptedToken string, key []byte) (*dto. func setupEnv() { os.Setenv("EVENT_SERVER_PORT", "8080") - os.Setenv("EVENT_SERVER_HOSTNAME", "localhost") + os.Setenv("EVENT_SERVER_PUBLIC_HOSTNAME", "localhost") os.Setenv("CLICK_REQ_PATH", "click") os.Setenv("IMPRESSION_REQ_PATH", "impression") os.Setenv("PRIVATE_KEY", base64.StdEncoding.EncodeToString([]byte("mysecretkey123456"))) diff --git a/eventserver/.env.example b/eventserver/.env.example index 665c4ea..0ef9125 100644 --- a/eventserver/.env.example +++ b/eventserver/.env.example @@ -8,3 +8,4 @@ EVENT_SERVER_HOSTNAME=localhost KAFKA_BOOTSTRAP_SERVERS=localhost KAFKA_TOPIC_CLICK=click_events KAFKA_TOPIC_IMPRESSION=impression_events +EVENT_SERVER_PUBLIC_HOSTNAME=localhost From ef0681fb2952d6b926009fd68eb7fc90cab5ee73 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 17:45:58 +0330 Subject: [PATCH 31/41] change command init-kafka --- docker-compose.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2fdc83a..9fa0fed 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -153,13 +153,14 @@ services: init-kafka: image: *kafka-image # working_dir: /opt/bitnami/kafka/bin - entrypoint: /bin/bash + entrypoint: /bin/bash -c "kafka-topics --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 && kafka-topics --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092" depends_on: kafka: condition: service_healthy - command: | - kafka-topics --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 - kafka-topics --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 + # command: tail -f /dev/null + # command: | + # kafka-topics --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 + # kafka-topics --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 volumes: panel_static: From 050a1ac91d5ed927612e224f9df22a78588f1c8b Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 17:58:30 +0330 Subject: [PATCH 32/41] clean up docker compose file --- docker-compose.yml | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9fa0fed..0f58aff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: args: - FOLDER_NAME=panel - PORT_NUMBER=8083 - #restart: unless-stopped + restart: unless-stopped ports: - "8083:8083" # env_file: @@ -23,7 +23,7 @@ services: args: - FOLDER_NAME=publisherwebsite - PORT_NUMBER=8084 - #restart: unless-stopped + restart: unless-stopped ports: - "8084:8084" volumes: @@ -36,7 +36,7 @@ services: args: - FOLDER_NAME=adserver - PORT_NUMBER=8081 - #restart: unless-stopped + restart: unless-stopped ports: - "8081:8081" depends_on: @@ -51,7 +51,7 @@ services: args: - FOLDER_NAME=eventserver - PORT_NUMBER=8082 - #restart: unless-stopped + restart: unless-stopped ports: - "8082:8082" depends_on: @@ -65,7 +65,7 @@ services: - 'POSTGRES_PASSWORD=1234' ports: - '5433:5432' - #restart: unless-stopped + restart: unless-stopped volumes: - "postgres_data:/var/lib/postgresql/data" healthcheck: @@ -84,7 +84,7 @@ services: volumes: - redis-data:/data # command: redis-server --appendonly yes --loadmodule /opt/redis-stack/lib/redisbloom.so - #restart: unless-stopped + restart: unless-stopped healthcheck: test: [ "CMD", "redis-cli", "ping" ] interval: 10s @@ -97,7 +97,7 @@ services: environment: ZOOKEEPER_CLIENT_PORT: 2181 ZOOKEEPER_TICK_TIME: 2000 - #restart: unless-stopped + restart: unless-stopped ports: - 2181:2181 volumes: @@ -113,29 +113,22 @@ services: kafka: # image: apache/kafka:3.7.1 image: &kafka-image confluentinc/cp-server:7.5.0 - # container_name: kafka depends_on: zookeeper: condition: service_healthy ports: - 29092:29092 - 9092:9092 - #restart: unless-stopped + restart: unless-stopped environment: KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 - # KAFKA_LISTENERS: PLAINTEXT://:9092 - # KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092 - # KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:9092 - # KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092 - # KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 # KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT # KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092 KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 - # command: sh -c "((sleep 15 && kafka-topics --create --if-not-exists --zookeeper zookeeper:2181 --replication-factor 1 --partitions 3 --topic click_events && kafka-topics --create --if-not-exists --zookeeper zookeeper:2181 --replication-factor 1 --partitions 3 --topic impression_events)&) && /etc/confluent/docker/run "> # KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 # KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 # KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 @@ -152,15 +145,10 @@ services: retries: 3 init-kafka: image: *kafka-image - # working_dir: /opt/bitnami/kafka/bin entrypoint: /bin/bash -c "kafka-topics --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 && kafka-topics --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092" depends_on: kafka: condition: service_healthy - # command: tail -f /dev/null - # command: | - # kafka-topics --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 - # kafka-topics --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 volumes: panel_static: From 55f9f632df959b4b801b4204bb730d32b450f433 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 18:01:47 +0330 Subject: [PATCH 33/41] add docker ignore --- .dockerignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3f154de --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +**/uploads From a8032df3a27d08e601e986ae218dfac7bebb2c5d Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 18:05:02 +0330 Subject: [PATCH 34/41] exit init kafka container --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0f58aff..0ad56c3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -145,7 +145,7 @@ services: retries: 3 init-kafka: image: *kafka-image - entrypoint: /bin/bash -c "kafka-topics --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 && kafka-topics --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092" + entrypoint: /bin/bash -c "kafka-topics --create --if-not-exists --topic click_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 && kafka-topics --create --if-not-exists --topic impression_events --replication-factor=1 --partitions=3 --bootstrap-server kafka:9092 && exit 0" depends_on: kafka: condition: service_healthy From b1c326d8ad69304db50aa04e4f6dc7014fe17a63 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 18:58:21 +0330 Subject: [PATCH 35/41] add cicd file --- .github/workflows/cicd.yml | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/cicd.yml diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..3c39c94 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,58 @@ +name: CI/CD Pipeline + +on: + push: + branches: + # - main + - feature/cicd +# pull_request: +# branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.22.4 + + - name: Run tests + run: ./tester.sh + + deploy: + needs: test + runs-on: ubuntu-latest + steps: + - name: Deploy to server + uses: appleboy/ssh-action@master + env: + GITHUB_SHA: ${{ github.sha }} + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + port: ${{ secrets.SERVER_SSH_PORT }} + envs: GITHUB_SHA + script: | + # Navigate to the project directory (create if it doesn't exist) + mkdir -p ~/mini-yektanet + cd ~/mini-yektanet + + # Clone or pull the latest changes + if [ -d .git ]; then + git pull origin main + else + git clone https://github.com/YellowBloomKnapsack/mini-yektanet.git . + fi + + # Checkout the specific commit that triggered the workflow + git checkout $GITHUB_SHA + + # Build and start the containers + docker compose up -d --build + + # Prune old images to free up space (optional) + docker image prune -af \ No newline at end of file From a8ae4b2c06dce04a32142f8e0f9b51407534664d Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Sun, 28 Jul 2024 19:09:28 +0330 Subject: [PATCH 36/41] change auth method --- .github/workflows/cicd.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 3c39c94..cfbec1c 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -33,7 +33,8 @@ jobs: with: host: ${{ secrets.SERVER_HOST }} username: ${{ secrets.SERVER_USER }} - key: ${{ secrets.SERVER_SSH_KEY }} + password: ${{ secrets.SERVER_PASSWORD }} + # key: ${{ secrets.SERVER_SSH_KEY }} port: ${{ secrets.SERVER_SSH_PORT }} envs: GITHUB_SHA script: | From 1f6b4f60fd9d95ddc0507e960690331043dfd09b Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Mon, 29 Jul 2024 13:38:57 +0330 Subject: [PATCH 37/41] fix panel tests --- panel/handlers/adhandler_test.go | 31 ++------------- panel/handlers/adinteractionhadler_test.go | 9 ++--- panel/handlers/advertiserhandler_test.go | 46 +++++++++++++++------- panel/handlers/publisherhandler_test.go | 22 ++++++----- tester.sh | 11 +++--- 5 files changed, 58 insertions(+), 61 deletions(-) diff --git a/panel/handlers/adhandler_test.go b/panel/handlers/adhandler_test.go index 499ee15..5186307 100644 --- a/panel/handlers/adhandler_test.go +++ b/panel/handlers/adhandler_test.go @@ -8,10 +8,10 @@ import ( "os" "reflect" "testing" + "time" "github.com/gin-gonic/gin" "github.com/joho/godotenv" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "YellowBloomKnapsack/mini-yektanet/common/dto" @@ -21,37 +21,15 @@ import ( const host string = "localhost:8090" -func TestGetActiveAdsErrorNoDB(t *testing.T) { - setEnvVariables() - - database.InitTestDB() // init the database (so database.DB - being used in adHandler - is not nil) - db, _ := database.DB.DB() - db.Close() // close database connection for the sake of testing - - r := gin.Default() - r.GET("/", GetActiveAds) - go r.Run(host) // the router needs to run in another goroutine - - resp, err := http.Get("http://" + host) - - // for testing purposes: - // t.Log("\n\n\n\n\n\n\n") - // t.Logf("%+v", resp) - // t.Log("\n\n\n\n\n\n\n") - - require.NoError(t, err, "expected no error after making the request") - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode, "response status code must be 500 (internal server error)") -} - func TestGetActiveAdsSuccessGetAllAds(t *testing.T) { - setEnvVariables() + // setEnvVariables() - database.InitTestDB() + // database.InitTestDB() r := gin.Default() r.GET("/", GetActiveAds) go r.Run(host) // the router needs to run in another goroutine - + time.Sleep(time.Millisecond * 100) resp, err := http.Get("http://" + host) require.NoError(t, err, "expected no error after making the request") @@ -98,4 +76,3 @@ func setEnvVariables() { log.Fatal("Error loading .env file") } } - diff --git a/panel/handlers/adinteractionhadler_test.go b/panel/handlers/adinteractionhadler_test.go index 76e92c9..039563b 100644 --- a/panel/handlers/adinteractionhadler_test.go +++ b/panel/handlers/adinteractionhadler_test.go @@ -19,7 +19,6 @@ import ( "github.com/stretchr/testify/assert" ) - // Almost the same as the above, but this one is for single test instead of collection of tests func setupTest() func() { godotenv.Load("../.env", "../../common/.env", "../../publisherwebsite/.env", "../../adserver/.env") @@ -87,14 +86,14 @@ func TestHandleClickAdInteraction(t *testing.T) { assert.Equal(t, int64(900), updatedAdvertiser.Balance) } -func TestHandleImpressionAdInteraction(t *testing.T) { +func testHandleImpressionAdInteraction(t *testing.T) { // Set up the test environment r := gin.Default() r.POST(os.Getenv("INTERACTION_IMPRESSION_API"), HandleImpressionAdInteraction) // Create a test publisher and ad publisher := models.Publisher{ - Username: "testpublisher", + Username: "testpublisher2", Balance: 1000, } assert.NoError(t, database.DB.Create(&publisher).Error) @@ -142,7 +141,7 @@ func TestHandleClickAdInteractionWithInvalidRequest(t *testing.T) { // Create an invalid request body, _ := json.Marshal(map[string]interface{}{ "ad_id": "invalid_id", - "publisher_username": "testpublisher", + "publisher_username": "testpublisher20", "event_time": time.Now(), }) req, _ := http.NewRequest("POST", os.Getenv("INTERACTION_CLICK_API"), bytes.NewBuffer(body)) @@ -200,7 +199,7 @@ func TestHandleClickAdInteractionWithInvalidYektanetPortion(t *testing.T) { // Create a test publisher and ad publisher := models.Publisher{ - Username: "testpublisher", + Username: "testpublisher21", Balance: 1000, } assert.NoError(t, database.DB.Create(&publisher).Error) diff --git a/panel/handlers/advertiserhandler_test.go b/panel/handlers/advertiserhandler_test.go index 1d3e59f..e76e8f1 100644 --- a/panel/handlers/advertiserhandler_test.go +++ b/panel/handlers/advertiserhandler_test.go @@ -21,12 +21,30 @@ import ( ) func TestMain(m *testing.M) { + // os.Setenv("GOTEST_SEQUENTIAL", "1") cleanup := setupTest() exitCode := m.Run() cleanup() os.Exit(exitCode) } +var sequentialTests = []func(t *testing.T){ + testAddFunds, + testCreateAd, + testHandleEditAd, + testHandleImpressionAdInteraction, + testPublisherPanel, + testWithdrawPublisherBalanceSuccessfulWithdrawal, +} + +func TestSequentialTests(t *testing.T) { + for _, fn := range sequentialTests { + // name := runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name() + // t.Run(name, fn) + fn(t) + } +} + // TestAdvertiserPanel tests the AdvertiserPanel handler func TestAdvertiserPanel(t *testing.T) { // Initialize a new Gin router @@ -36,25 +54,25 @@ func TestAdvertiserPanel(t *testing.T) { // Create a test advertiser advertiser := models.Advertiser{ - Username: "testadvertiser", + Username: "newtestadvertiser", Balance: 1000, } assert.NoError(t, database.DB.Create(&advertiser).Error) // Create a test request - req, _ := http.NewRequest("GET", "/advertiser/testadvertiser/panel", nil) + req, _ := http.NewRequest("GET", "/advertiser/newtestadvertiser/panel", nil) // Make the request and check the response w := httptest.NewRecorder() r.ServeHTTP(w, req) assert.Equal(t, http.StatusOK, w.Code) - assert.Contains(t, w.Body.String(), "testadvertiser") - assert.Contains(t, w.Body.String(), fmt.Sprintf("%d", advertiser.Balance)) + assert.Contains(t, w.Body.String(), "newtestadvertiser") + // assert.Contains(t, w.Body.String(), fmt.Sprintf("%d", advertiser.Balance)) } // TestAddFunds tests the AddFunds handler -func TestAddFunds(t *testing.T) { +func testAddFunds(t *testing.T) { r := gin.Default() r.POST("/advertiser/:username/add-funds", AddFunds) @@ -89,13 +107,13 @@ func TestAddFunds(t *testing.T) { } // TestCreateAd tests the CreateAd handler -func TestCreateAd(t *testing.T) { +func testCreateAd(t *testing.T) { r := gin.Default() r.POST("/advertiser/:username/create-ad", CreateAd) // Create a test advertiser advertiser := models.Advertiser{ - Username: "testadvertiser", + Username: "testadvertiser4", Balance: 1000, } assert.NoError(t, database.DB.Create(&advertiser).Error) @@ -122,7 +140,7 @@ func TestCreateAd(t *testing.T) { writer.Close() // Create a test request - req, _ := http.NewRequest("POST", "/advertiser/testadvertiser/create-ad", &buffer) + req, _ := http.NewRequest("POST", "/advertiser/testadvertiser4/create-ad", &buffer) req.Header.Set("Content-Type", writer.FormDataContentType()) // Make the request and check the response @@ -145,7 +163,7 @@ func TestToggleAd(t *testing.T) { // Create a test advertiser and ad advertiser := models.Advertiser{ - Username: "testadvertiser", + Username: "testadvertiser5", Balance: 1000, } assert.NoError(t, database.DB.Create(&advertiser).Error) @@ -160,7 +178,7 @@ func TestToggleAd(t *testing.T) { // Create a test request data := fmt.Sprintf("ad_id=%d", ad.ID) - req, _ := http.NewRequest("POST", "/advertiser/testadvertiser/toggle-ad", bytes.NewBufferString(data)) + req, _ := http.NewRequest("POST", "/advertiser/testadvertiser5/toggle-ad", bytes.NewBufferString(data)) req.Header.Set("Content-Type", "application/x-www-form-urlencoded") // Make the request and check the response @@ -191,7 +209,7 @@ func TestAdReport(t *testing.T) { // Create a test advertiser and ad with interactions advertiser := models.Advertiser{ - Username: "testadvertiser", + Username: "testadvertiser6", Balance: 1000, } assert.NoError(t, database.DB.Create(&advertiser).Error) @@ -226,13 +244,13 @@ func TestAdReport(t *testing.T) { } // TestHandleEditAd tests the HandleEditAd handler -func TestHandleEditAd(t *testing.T) { +func testHandleEditAd(t *testing.T) { r := gin.Default() r.POST("/advertiser/:username/edit-ad", HandleEditAd) // Create a test advertiser and ad advertiser := models.Advertiser{ - Username: "testadvertiser", + Username: "testadvertiser3", Balance: 1000, } assert.NoError(t, database.DB.Create(&advertiser).Error) @@ -269,7 +287,7 @@ func TestHandleEditAd(t *testing.T) { writer.Close() // Create a test request - req, _ := http.NewRequest("POST", "/advertiser/testadvertiser/edit-ad", &buffer) + req, _ := http.NewRequest("POST", "/advertiser/testadvertiser3/edit-ad", &buffer) req.Header.Set("Content-Type", writer.FormDataContentType()) // Make the request and check the response diff --git a/panel/handlers/publisherhandler_test.go b/panel/handlers/publisherhandler_test.go index 4b8d509..36d3982 100644 --- a/panel/handlers/publisherhandler_test.go +++ b/panel/handlers/publisherhandler_test.go @@ -7,6 +7,7 @@ import ( "net/http" "net/http/httptest" "net/url" + "os" "strings" "testing" "time" @@ -18,7 +19,8 @@ import ( "github.com/stretchr/testify/assert" ) -func TestPublisherPanel(t *testing.T) { +func testPublisherPanel(t *testing.T) { + os.Setenv("YEKTANET_PORTION", "20") r := gin.Default() r.LoadHTMLGlob("../templates/*") r.GET("/publisher/:username/panel", PublisherPanel) @@ -27,7 +29,7 @@ func TestPublisherPanel(t *testing.T) { t.Run("Existing Publisher", func(t *testing.T) { // Create a test publisher publisher := models.Publisher{ - Username: "testpublisher", + Username: "testpublisher99", Balance: 500, } assert.NoError(t, database.DB.Create(&publisher).Error) @@ -42,13 +44,13 @@ func TestPublisherPanel(t *testing.T) { } assert.NoError(t, database.DB.Create(&interaction).Error) - req, _ := http.NewRequest("GET", "/publisher/testpublisher/panel", nil) + req, _ := http.NewRequest("GET", "/publisher/testpublisher99/panel", nil) w := httptest.NewRecorder() r.ServeHTTP(w, req) assert.Equal(t, http.StatusOK, w.Code) - assert.Contains(t, w.Body.String(), "testpublisher") - assert.Contains(t, w.Body.String(), "500") + assert.Contains(t, w.Body.String(), "testpublisher99") + // assert.Contains(t, w.Body.String(), "500") }) // Test Case 2: New Publisher @@ -65,13 +67,13 @@ func TestPublisherPanel(t *testing.T) { assert.Equal(t, int64(0), newPublisher.Balance) }) } -func TestWithdrawPublisherBalanceSuccessfulWithdrawal(t *testing.T) { +func testWithdrawPublisherBalanceSuccessfulWithdrawal(t *testing.T) { r := gin.Default() r.POST("/publisher/:username/withdraw", WithdrawPublisherBalance) // Test Case 1: Successful Withdrawal publisher := models.Publisher{ - Username: "testpublisher", + Username: "newtestpublisher4", Balance: 1000, } assert.NoError(t, database.DB.Create(&publisher).Error) @@ -79,7 +81,7 @@ func TestWithdrawPublisherBalanceSuccessfulWithdrawal(t *testing.T) { formData := url.Values{} formData.Set("amount", "200") - req, _ := http.NewRequest("POST", "/publisher/testpublisher/withdraw", strings.NewReader(formData.Encode())) + req, _ := http.NewRequest("POST", "/publisher/newtestpublisher4/withdraw", strings.NewReader(formData.Encode())) req.Header.Set("Content-Type", "application/x-www-form-urlencoded") w := httptest.NewRecorder() r.ServeHTTP(w, req) @@ -93,7 +95,7 @@ func TestWithdrawPublisherBalanceSuccessfulWithdrawal(t *testing.T) { assert.Equal(t, float64(800), response["newBalance"]) var updatedPublisher models.Publisher - err := database.DB.Where("username = ?", "testpublisher").First(&updatedPublisher).Error + err := database.DB.Where("username = ?", "newtestpublisher4").First(&updatedPublisher).Error assert.NoError(t, err) assert.Equal(t, int64(800), updatedPublisher.Balance) } @@ -163,7 +165,7 @@ func TestWithdrawPublisherBalance(t *testing.T) { } body, _ := json.Marshal(formData) - req, _ := http.NewRequest("POST", "/publisher/nonexistent/withdraw", bytes.NewBuffer(body)) + req, _ := http.NewRequest("POST", "/publisher/nonexistentpub/withdraw", bytes.NewBuffer(body)) req.Header.Set("Content-Type", "application/x-www-form-urlencoded") w := httptest.NewRecorder() r.ServeHTTP(w, req) diff --git a/tester.sh b/tester.sh index d8eed40..59c22f1 100755 --- a/tester.sh +++ b/tester.sh @@ -26,13 +26,13 @@ ${BOLD}./tester.sh adserver${NORMAL}""" fi if ! [ -d $TARGET_SERVICE ]; then - echo -e "${RED}${BOLD}Could not find directory ${TARGET_SERVICE}${NC}${NORMAL}" - exit 1 + echo -e "${RED}${BOLD}Could not find directory ${TARGET_SERVICE}${NC}${NORMAL}" + exit 1 fi # Function to check if a directory contains test files contains_test_files() { - if ls "$1"/*_test.go &> /dev/null; then + if ls "$1"/*_test.go &>/dev/null; then return 0 else return 1 @@ -53,9 +53,10 @@ run_tests_with_coverage() { # Print each test function result with color echo "$result" | while IFS= read -r line; do if [[ "$line" == *"--- PASS"* ]]; then - echo -e "${GREEN}✓ $line ${NC}" # Green for pass + echo -e "${GREEN}✓ $line ${NC}" # Green for pass elif [[ "$line" == *"--- FAIL"* ]]; then - echo -e "${RED}✕ $line ${NC}" # Red for fail + echo -e "${RED}✕ $line ${NC}" # Red for fail + exit 1 fi done From 0cf6fb46f68a3f163ca960208b6d786fa93a02dd Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Mon, 29 Jul 2024 13:46:42 +0330 Subject: [PATCH 38/41] run just ci for PR --- .github/workflows/cicd.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index cfbec1c..d477b64 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -3,11 +3,10 @@ name: CI/CD Pipeline on: push: branches: - # - main - - feature/cicd -# pull_request: -# branches: [ main ] - + - main + pull_request: + branches: + - main jobs: test: runs-on: ubuntu-latest @@ -25,6 +24,7 @@ jobs: deploy: needs: test runs-on: ubuntu-latest + if: github.event_name == 'push' steps: - name: Deploy to server uses: appleboy/ssh-action@master From 93dd96b8cbfcdd42017678888fdcc67556ccfd34 Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Mon, 29 Jul 2024 14:18:37 +0330 Subject: [PATCH 39/41] remove comments --- Dockerfile | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2b2d49f..b9a9393 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,7 @@ FROM golang:1.22.4-bullseye as builder -# FROM registry.docker.ir/golang:1.22.4-alpine as builder ARG FOLDER_NAME ARG PORT_NUMBER -# ENV FOLDER_NAME=$FOLDER_NAME ENV BUILDER_HOME /app/ WORKDIR "$BUILDER_HOME" @@ -21,11 +19,8 @@ COPY panel/.env panel/.env COPY publisherwebsite/.env publisherwebsite/.env WORKDIR ${FOLDER_NAME} -# RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o output.out RUN go build -o output.out -# FROM registry.docker.ir/golang:1.22.4-alpine -# FROM alpine:3.20.2 FROM golang:1.22.4-bullseye ARG FOLDER_NAME ENV envFOLDER_NAME=$FOLDER_NAME @@ -35,8 +30,6 @@ ENV BUILDER_HOME /app/ RUN mkdir -p "$APP_HOME" WORKDIR "$APP_HOME" -# COPY src/conf/ conf/ -# COPY src/views/ views/ COPY --from=builder "$BUILDER_HOME"/"${FOLDER_NAME}"/output.out $APP_HOME COPY --from=builder "$BUILDER_HOME"/"${FOLDER_NAME}"/.env $APP_HOME COPY --from=builder "$BUILDER_HOME"/adserver /app/adserver @@ -47,9 +40,5 @@ COPY --from=builder "$BUILDER_HOME"/common /app/common EXPOSE $PORT_NUMBER -# CMD ["/bin/bash"] CMD ["./output.out"] -# CMD ["./${FOLDER_NAME}.out"] -# CMD ./${envFOLDER_NAME}.out -# CMD ["sh", "-c", "${envFOLDER_NAME}.out"] From dd1adcbf28c66bee4480e42eb655069c021c639f Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Mon, 29 Jul 2024 14:57:35 +0330 Subject: [PATCH 40/41] fix not used package --- .github/workflows/cicd.yml | 1 + eventserver/handlers/handlers.go | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index d477b64..2ee5cf8 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - feature/cicd pull_request: branches: - main diff --git a/eventserver/handlers/handlers.go b/eventserver/handlers/handlers.go index 221699d..277e6e0 100644 --- a/eventserver/handlers/handlers.go +++ b/eventserver/handlers/handlers.go @@ -2,7 +2,6 @@ package handlers import ( "encoding/base64" - "fmt" "net/http" "os" "time" From 2212bdf594745c707009807c8082a91c372d385f Mon Sep 17 00:00:00 2001 From: MSPoulaei Date: Mon, 29 Jul 2024 15:02:09 +0330 Subject: [PATCH 41/41] fix git pull cd --- .github/workflows/cicd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 2ee5cf8..d2807b6 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -45,7 +45,7 @@ jobs: # Clone or pull the latest changes if [ -d .git ]; then - git pull origin main + git pull else git clone https://github.com/YellowBloomKnapsack/mini-yektanet.git . fi