-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from YellowBloomKnapsack/feature/cicd
Feature/cicd
- Loading branch information
Showing
26 changed files
with
366 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/uploads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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 | ||
if: github.event_name == 'push' | ||
steps: | ||
- name: Deploy to server | ||
uses: appleboy/ssh-action@master | ||
env: | ||
GITHUB_SHA: ${{ github.sha }} | ||
with: | ||
host: ${{ secrets.SERVER_HOST }} | ||
username: ${{ secrets.SERVER_USER }} | ||
password: ${{ secrets.SERVER_PASSWORD }} | ||
# 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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,5 @@ | |
.idea | ||
|
||
**/test*.db | ||
|
||
**/*.private.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
FROM golang:1.22.4-bullseye as builder | ||
|
||
ARG FOLDER_NAME | ||
ARG PORT_NUMBER | ||
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 | ||
COPY adserver/.env adserver/.env | ||
COPY eventserver/.env eventserver/.env | ||
COPY panel/.env panel/.env | ||
COPY publisherwebsite/.env publisherwebsite/.env | ||
|
||
WORKDIR ${FOLDER_NAME} | ||
RUN go build -o output.out | ||
|
||
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 --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 ["./output.out"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
services: | ||
panel: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
- FOLDER_NAME=panel | ||
- PORT_NUMBER=8083 | ||
restart: unless-stopped | ||
ports: | ||
- "8083:8083" | ||
# 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 | ||
restart: unless-stopped | ||
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 | ||
restart: unless-stopped | ||
ports: | ||
- "8081:8081" | ||
depends_on: | ||
kafka: | ||
condition: service_healthy | ||
panel: | ||
condition: service_started | ||
eventserver: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
- FOLDER_NAME=eventserver | ||
- PORT_NUMBER=8082 | ||
restart: unless-stopped | ||
ports: | ||
- "8082:8082" | ||
depends_on: | ||
kafka: | ||
condition: service_healthy | ||
db: | ||
image: 'postgres:15.7-alpine' | ||
environment: | ||
- 'POSTGRES_DB=mini_yektanet_db' | ||
- 'POSTGRES_USER=postgres' | ||
- 'POSTGRES_PASSWORD=1234' | ||
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 | ||
redis: | ||
# 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 | ||
restart: unless-stopped | ||
healthcheck: | ||
test: [ "CMD", "redis-cli", "ping" ] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 3 | ||
start_period: 30s | ||
zookeeper: | ||
# image: zookeeper:3.8.4 | ||
image: confluentinc/cp-zookeeper:7.5.0 | ||
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 | ||
image: &kafka-image confluentinc/cp-server:7.5.0 | ||
depends_on: | ||
zookeeper: | ||
condition: service_healthy | ||
ports: | ||
- 29092:29092 | ||
- 9092:9092 | ||
restart: unless-stopped | ||
environment: | ||
KAFKA_BROKER_ID: 1 | ||
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 | ||
# 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 | ||
# 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 | ||
- kafka-docker-sock:/var/run/docker.sock | ||
healthcheck: | ||
test: kafka-topics --bootstrap-server kafka:9092 --list | ||
interval: 30s | ||
timeout: 10s | ||
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 && exit 0" | ||
depends_on: | ||
kafka: | ||
condition: service_healthy | ||
|
||
volumes: | ||
panel_static: | ||
postgres_data: | ||
publisherwebsite_static: # publisherwebsite_html: | ||
redis-data: | ||
zookeeper-data: | ||
zookeeper-logs: | ||
kafka-data: | ||
kafka-docker-sock: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package handlers | |
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"time" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.