Skip to content

Commit

Permalink
Add auto docker build using github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Divkix committed Apr 1, 2022
1 parent 917381b commit c3df79f
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 7 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Docker Build

on:
push:
branches:
- main
paths:
- Dockerfile
- .dockerignore
- .github/workflows/docker-build.yml
- "*.go"
workflow_dispatch:

jobs:
build:
name: Build Image
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- name: Checkout current repo
uses: actions/checkout@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set ENV Variables
run: |
IMG="$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')"
echo "IMAGE=${IMG}" >> $GITHUB_ENV
echo "GIT_SHA=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV
echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/${{ env.IMAGE }}:latest
ghcr.io/${{ env.IMAGE }}:${{ env.GIT_SHA }}
${{ env.IMAGE }}:latest
${{ env.IMAGE }}:${{ env.GIT_SHA }}
labels: |
org.opencontainers.image.authors=${{ github.repository_owner }}
org.opencontainers.image.created=${{ env.BUILD_DATE }}
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ env.GIT_SHA }}
23 changes: 23 additions & 0 deletions .github/workflows/update-docker-readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Update Docker Hub Description

on:
push:
branches:
- main
paths:
- README.md
- .github/workflows/update-docker-readme.yml

jobs:
build-image:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Build Stage: Build bot using the alpine image, also install doppler in it
FROM golang:1.18.0-alpine3.15 AS builder
RUN apk add --update --no-cache git
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 GOOS=`go env GOHOSTOS` GOARCH=`go env GOHOSTARCH` go build -o out/RestrictChannelRobot

# Run Stage: Run bot using the bot and doppler binary copied from build stage
FROM gcr.io/distroless/static
COPY --from=builder /app/out/RestrictChannelRobot /

CMD ["/RestrictChannelRobot"]
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
# Restrict Channel Robot

<p align='center'>
<img src="https://img.shields.io/github/forks/DivideProjects/restrictchannelrobot?style=flat-square" alt="Forks">
<img src="https://img.shields.io/github/stars/DivideProjects/restrictchannelrobot?style=flat-square" alt="Stars">
<img src="https://img.shields.io/github/issues/DivideProjects/restrictchannelrobot?style=flat-square" alt="Issues">
<img src="https://img.shields.io/github/license/DivideProjects/restrictchannelrobot?style=flat-square" alt="LICENSE">
<img src="https://img.shields.io/github/contributors/DivideProjects/restrictchannelrobot?style=flat-square" alt="Contributors">
<img src="https://img.shields.io/github/repo-size/DivideProjects/restrictchannelrobot?style=flat-square" alt="Repo Size">
<img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https://github.com/DivideProjects/restrictchannelrobot&amp;title=Profile%20Views" alt="Views">
</p>

<p align='center'>
<a href="https://go.dev/" alt="made-with-go"> <img src="https://img.shields.io/badge/Made%20with-Go-1f425f.svg?style=flat-square&logo=go&color=blue" /> </a>
<a href="https://github.com/DivideProjects/restrictchannelrobot" alt="Docker!"> <img src="https://img.shields.io/docker/pulls/divideprojects/restrictchannelrobot.svg" /> </a>
<a href="https://hub.docker.com/r/divideprojects/restrictchannelrobot" alt="Docker Image Version"> <img src="https://img.shields.io/docker/v/divideprojects/restrictchannelrobot/latest" /> </a>
<a href="https://deepsource.io/gh/DivideProjects/restrictchannelrobot/?ref=repository-badge"><img src="https://static.deepsource.io/deepsource-badge-light-mini.svg" alt="DeepSource"></a>
</p>


Telegram Bot, written in GoLang to delete messages and ban anonymous users who send as channel in groups.

Can be found on telegram as [@RestrictChannelRobot](https://telegram.dog/RestrictChannelRobot)
Expand All @@ -14,14 +33,9 @@ Can be found on telegram as [@RestrictChannelRobot](https://telegram.dog/Restric

## Deploy via Heroku.
<p>
<a href="https://heroku.com/deploy?template=https://github.com/DivideProjects/RestrictChannelRobot"><img src="https://www.herokucdn.com/deploy/button.svg" alt="Deploy"></a>
<a href="https://heroku.com/deploy?template=https://github.com/DivideProjects/restrictchannelrobot"><img src="https://www.herokucdn.com/deploy/button.svg" alt="Deploy"></a>
</p>

## Deploy via Dockerfile
Make sure to change the CMD to `["/RestrictChannelRobot"]`

Otherwise the bot may not work!

## Support
Join the [Telegram Group](https://t.me/DivideProjectsDiscussion) for support and the [Channel](https://t.me/DivideProjects) for updates.

Expand Down

0 comments on commit c3df79f

Please sign in to comment.