From 655f81dcc70b1bcdca20e46607834d672038faa8 Mon Sep 17 00:00:00 2001 From: Anton Zavodchikov Date: Fri, 21 Oct 2022 19:29:03 +0600 Subject: [PATCH] Docker build file and CD workflow --- .dockerignore | 17 ++++++++++++++ .github/workflows/build.yml | 45 +++++++++++++++++++++++++++++++++++++ Dockerfile | 26 +++++++++++++++++++++ README.md | 6 +++++ docker-compose.dev.yaml | 11 +++++++++ docker-compose.yaml | 16 +++++++++++++ 6 files changed, 121 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile create mode 100644 docker-compose.dev.yaml create mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..02eb176 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +*.secret +*.env + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f296664 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,45 @@ +name: Build and push + +on: + push: + branches: + - 'master' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - + name: Build and push + uses: docker/build-push-action@v3 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: . + push: true + platforms: linux/amd64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..453c513 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM golang:1.17-alpine AS build_base + +RUN apk add --no-cache alpine-sdk + +# Set the Current Working Directory inside the container +WORKDIR /app + +# We want to populate the module cache based on the go.{mod,sum} files. +COPY go.mod . +COPY go.sum . + +RUN go mod download + +COPY . . + +RUN go build -o /out/bot . + +FROM alpine:latest + +WORKDIR /app + +RUN apk add ca-certificates +COPY --from=build_base /out/bot ./bot + +EXPOSE 8080 +CMD ["/app/bot"] \ No newline at end of file diff --git a/README.md b/README.md index b086adf..bf47c50 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,9 @@ Blockchain part is generated from IKY repo, see it for more details about contra 3. User go to webapp page, make transaction, submitting it's tgid 4. Bot get event about it from blockchain 5. Bot verifies registration + +## Deploy with Docker + +1. Copy `.envExample` into `.env` and fill it with your values +2. Run with `docker-compose up -d` +3. Done diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml new file mode 100644 index 0000000..6a5c787 --- /dev/null +++ b/docker-compose.dev.yaml @@ -0,0 +1,11 @@ +version: "3.9" + +services: + bot: + container_name: verifier-bot + image: verifier-bot + build: + dockerfile: Dockerfile + restart: always + volumes: + - ".env:/app/.env" \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..feae51c --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,16 @@ +version: "3.9" + +services: + bot: + container_name: verifier-bot + image: ghcr.io/0xsolidarnost/verifier-bot:master + restart: always + volumes: + - ".env:/app/.env" + + watchtower: + image: containrrr/watchtower + command: --interval 300 --include-stopped --include-restarting --cleanup + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ~/.docker/config.json:/config.json \ No newline at end of file