Skip to content

Commit

Permalink
update Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad Shafiee committed Aug 8, 2024
1 parent 40152ce commit a33b253
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 43 deletions.
9 changes: 2 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use the official Go image as a parent image
FROM golang:1.21 as builder
FROM golang:1.21 AS builder

# Set the working directory
WORKDIR /app
Expand All @@ -12,7 +12,7 @@ RUN go mod download && \
go build -o /app/webBridgeBot .

# Use a smaller image to run the app
FROM debian:bookworm-slim
FROM debian:bookworm-slim AS final

# Set the working directory
WORKDIR /app
Expand All @@ -27,11 +27,6 @@ COPY run.sh /app/run.sh
RUN chmod +x /app/webBridgeBot
RUN chmod +x /app/run.sh

# Update and install the necessary libraries
RUN apt-get update && apt-get install -y \
libssl3 \
&& rm -rf /var/lib/apt/lists/*

# Expose the application's port
EXPOSE 8080

Expand Down
38 changes: 3 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,16 @@
# Makefile for cloning, building TDLib, building OpenSSL, and building a Go application (webBridgeBot) that uses TDLib

# Define variables
TDLIB_GIT_REPO=https://github.com/tdlib/td.git
OPENSSL_GIT_REPO=https://github.com/openssl/openssl.git
OPENSSL_VERSION=openssl-3.0.0
TDLIB_DIR=$(CURDIR)/tdlib
OPENSSL_DIR=$(CURDIR)/openssl
BUILD_DIR=$(TDLIB_DIR)/build
TDLIB_INSTALL_DIR=$(CURDIR)/tdlib_install
OPENSSL_INSTALL_DIR=$(CURDIR)/openssl_install
DOCKER_IMAGE_NAME=webbridgebot
DOCKER_TAG=latest
DOCKER_USERNAME=mshafiee

# Environment variables for Go build
export CGO_CFLAGS=-I$(TDLIB_INSTALL_DIR)/include -I$(OPENSSL_INSTALL_DIR)/include
export CGO_LDFLAGS=-L$(TDLIB_INSTALL_DIR)/lib -L$(OPENSSL_INSTALL_DIR)/lib -lssl -lcrypto

# Default target builds OpenSSL, TDLib, the Go application, and the Docker image
all: openssl tdlib webBridgeBot docker

# Clone and build OpenSSL
openssl:
git clone --depth 1 --branch $(OPENSSL_VERSION) $(OPENSSL_GIT_REPO) $(OPENSSL_DIR) && \
cd $(OPENSSL_DIR) && \
./config --prefix=$(OPENSSL_INSTALL_DIR) && \
make && make install

# Clone TDLib repository
$(TDLIB_DIR):
git clone --depth 1 $(TDLIB_GIT_REPO) $(TDLIB_DIR)

# Build TDLib
tdlib: openssl $(TDLIB_DIR)
mkdir -p $(BUILD_DIR) && cd $(BUILD_DIR) && \
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$(TDLIB_INSTALL_DIR) -DOPENSSL_ROOT_DIR=$(OPENSSL_INSTALL_DIR) .. && \
cmake --build . --target install
all: webBridgeBot docker

# Build the Go application webBridgeBot
webBridgeBot: tdlib
webBridgeBot:
go build -o webBridgeBot .

# Build Docker image
Expand All @@ -53,11 +25,7 @@ docker:
# Clean up build and cloned directories, and remove webBridgeBot binary
clean:
rm -rf $(BUILD_DIR)
rm -rf $(TDLIB_DIR)
rm -rf $(OPENSSL_DIR)
rm -rf $(TDLIB_INSTALL_DIR)
rm -rf $(OPENSSL_INSTALL_DIR)
rm -f webBridgeBot

# Phony targets
.PHONY: all clean tdlib webBridgeBot openssl docker
.PHONY: all clean webBridgeBot docker
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ services:
- BOT_TOKEN=${BOT_TOKEN}
- BASE_URL=${BASE_URL}
- PORT=${PORT}
- HASH_LENGTH=${HASH_LENGTH}
- MAX_CACHE_SIZE=${MAX_CACHE_SIZE}
- PORT=${PORT}
ports:
- "${PORT}:${PORT}"
volumes:
- .tdlib:/app/.tdlib # Persist TDLib data between container restarts
- .cache:/app/.cache # Persist .cache data between container restarts

0 comments on commit a33b253

Please sign in to comment.