Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ksssomesh12 committed Jul 10, 2021
0 parents commit 011c367
Show file tree
Hide file tree
Showing 17 changed files with 2,071 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.gitignore
.github
deploy
132 changes: 132 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: build-docker-image

on: [push, workflow_dispatch]

jobs:
build-base-image:
runs-on: ubuntu-latest
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ksssomesh12
password: ${{ secrets.GH_PACKAGES_TOKEN }}

- name: Setup Docker Buildx
id: setup_buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker Layers
id: cache_docker_layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-app-base-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx-app-base-

- name: Build-Push Docker Image
id: docker_build_push
uses: docker/build-push-action@v2
with:
builder: ${{ steps.setup_buildx.outputs.name }}
target: app-base
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
push: true
tags: ghcr.io/ksssomesh12/tgmb-beta:app-base

- name: Move Docker Layer Cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build-compile-image:
runs-on: ubuntu-latest
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ksssomesh12
password: ${{ secrets.GH_PACKAGES_TOKEN }}

- name: Setup Docker Buildx
id: setup_buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker Layers
id: cache_docker_layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-app-compile-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx-app-compile-

- name: Build-Push Docker Image
id: docker_build_push
uses: docker/build-push-action@v2
with:
builder: ${{ steps.setup_buildx.outputs.name }}
target: app-compile
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
push: true
tags: ghcr.io/ksssomesh12/tgmb-beta:app-compile

- name: Docker Image Digest
run: echo ${{ steps.docker_build_push.outputs.digest }}

- name: Move Docker Layer Cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
build-final-image:
runs-on: ubuntu-latest
needs: [build-base-image, build-compile-image]
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ksssomesh12
password: ${{ secrets.GH_PACKAGES_TOKEN }}

- name: Setup Docker Buildx
id: setup_buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker Layers
id: cache_docker_layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-app-final-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx-app-final-

- name: Get Branch/Tag Ref
id: get_ref
shell: bash
run: echo "##[set-output name=ref;]$(echo ${GITHUB_REF##*/})"

- name: Build-Push Docker Image
id: docker_build_push
uses: docker/build-push-action@v2
with:
builder: ${{ steps.setup_buildx.name }}
target: app-final
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
push: true
tags: |
ghcr.io/ksssomesh12/tgmb-beta:${{ github.sha }}
ghcr.io/ksssomesh12/tgmb-beta:${{ steps.get_ref.outputs.ref }}
- name: Docker Image Digest
run: echo ${{ steps.docker_build_push.outputs.digest }}

- name: Move Docker Layer Cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
21 changes: 21 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: create-release

on:
push:
tags:
- "v*.*"

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
29 changes: 29 additions & 0 deletions .github/workflows/deploy-heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: deploy-heroku

on: workflow_dispatch

jobs:
deploy-heroku:
runs-on: ubuntu-latest
steps:
- name: Setup Docker Buildx
id: setup_buildx
uses: docker/setup-buildx-action@v1
with:
driver: docker
install: true

- name: Build-Push-Release App to Heroku
env:
DYNAMIC_ENV_FILEID: ${{ secrets.DYNAMIC_ENV_FILEID }}
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
run: |
heroku container:login
echo "FROM ghcr.io/ksssomesh12/tgmb-beta:master
COPY . .
" >> Dockerfile
echo "https://docs.google.com/uc?export=download&id=$DYNAMIC_ENV_FILEID" | aria2c --input-file=-
docker build . -t registry.heroku.com/$HEROKU_APP_NAME/worker --progress=plain
docker push registry.heroku.com/$HEROKU_APP_NAME/worker
heroku container:release worker -a $HEROKU_APP_NAME
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM ubuntu:latest as app-base
ENV DEBIAN_FRONTEND='noninteractive'
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y aria2 curl jq libc++-dev locales nano pv python3 python3-pip python3-lxml tzdata && \
apt-get clean && rm -rf /var/lib/apt/lists/*
RUN locale-gen en_US.UTF-8
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8' TZ='Asia/Kolkata'

FROM ubuntu:latest as app-compile
ENV DEBIAN_FRONTEND='noninteractive'
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y git gperf make cmake clang-10 libc++-dev libc++abi-dev libssl-dev zlib1g-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/*
WORKDIR /root
RUN git clone --recursive https://github.com/tdlib/telegram-bot-api.git && \
cd telegram-bot-api && git checkout 81f2983 && mkdir build && cd build && \
CXXFLAGS="-stdlib=libc++" CC=/usr/bin/clang-10 CXX=/usr/bin/clang++-10 \
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && \
cmake --build . --target install -- -j $(nproc) && \
cd ../.. && rm -rf telegram-bot-api && \
ls -l /usr/bin/telegram-bot-api*

FROM ghcr.io/ksssomesh12/tgmb-beta:app-base as base
FROM ghcr.io/ksssomesh12/tgmb-beta:app-compile as compile

FROM scratch as app-final
COPY --from=base / /
COPY --from=compile /usr/bin/telegram-bot-api /usr/bin
WORKDIR /usr/src/app
RUN chmod 777 /usr/src/app
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python3", "-m", "tgmb"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# tgmb-beta

[![build-docker-image](https://github.com/ksssomesh12/tgmb-beta/actions/workflows/build-docker-image.yml/badge.svg)](https://github.com/ksssomesh12/tgmb-beta/actions/workflows/build-docker-image.yml)
2 changes: 2 additions & 0 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM ghcr.io/ksssomesh12/tgmb-beta:master
COPY . .
8 changes: 8 additions & 0 deletions deploy/config_sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
botToken = ""
botOwnerId = ""
telegramApiId = ""
telegramApiHash = ""
googleDriveFolderId = ""
authorizedChats = ""
ariaRpcSecret = "tgmb-beta"
dlRootDir = "dl"
3 changes: 3 additions & 0 deletions deploy/heroku.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
docker:
worker: Dockerfile
Loading

0 comments on commit 011c367

Please sign in to comment.