Add dockerfile and CI

This commit is contained in:
Melora Hugues 2023-03-11 16:21:03 +01:00
parent f2bff1fd80
commit a39c3f3087
6 changed files with 112 additions and 6 deletions

90
.drone.yml Normal file
View file

@ -0,0 +1,90 @@
---
# Test building the code and docker image
kind: pipeline
type: docker
name: test-build
steps:
- name: go-test
image: golang
commands:
- make -C notifier test
depends_on:
- name: go-build
image: golang
commands:
- make -C notifier build
depends_on:
- name: docker-build-only
image: thegeeklab/drone-docker-buildx
privileged: true
settings:
repo: git.faercol.me/faercol/telegram-notifier
tags: latest
dry_run: true
platforms:
- linux/amd64
- linux/arm64
depends_on:
when:
branch:
exclude:
- main
- name: docker-build-push
image: thegeeklab/drone-docker-buildx
privileged: true
settings:
repo: git.faercol.me/faercol/telegram-notifier
registry: git.faercol.me
tags: latest
username:
from_secret: GIT_USERNAME
password:
from_secret: GIT_PASSWORD
platforms:
- linux/amd64
- linux/arm64
depends_on:
- go-test
- go-build
when:
branch:
- main
trigger:
event:
- push
- tag
---
# On a tag, only build the related docker image
kind: pipeline
type: docker
name: tag-release
depends_on:
- test-build
steps:
- name: docker-push-tag
image: thegeeklab/drone-docker-buildx
privileged: true
settings:
registry: git.faercol.me
repo: git.faercol.me/faercol/teelgram-notifier
auto_tag: true
platforms:
- linux/amd64
- linux/arm64
username:
from_secret: GIT_USERNAME
password:
from_secret: GIT_PASSWORD
trigger:
event:
- tag
...

16
Dockerfile Normal file
View file

@ -0,0 +1,16 @@
FROM --platform=$TARGETPLATFORM golang:1.20 AS builder
ARG TARGETPLATFORM
ARG BUILDPLATFORM
WORKDIR /go/src/git.faercol.me/telegram-notifier/
COPY notifier ./
RUN CGO_ENABLED=0 make build
# Replace with from scratch later on
FROM --platform=$TARGETPLATFORM alpine:latest
WORKDIR /root
COPY --from=builder go/src/git.faercol.me/telegram-notifier/build/notifier ./
VOLUME [ "/config" "/input" ]
ENTRYPOINT [ "./notifier" ]
CMD [ "-config", "/config/config.json" ]

View file

@ -6,10 +6,10 @@ import (
"os" "os"
"os/signal" "os/signal"
"git.faercol.me/faercol/telegram-notifier/notifier/notifier/config" "git.faercol.me/faercol/telegram-notifier/notifier/config"
"git.faercol.me/faercol/telegram-notifier/notifier/notifier/listener" "git.faercol.me/faercol/telegram-notifier/notifier/listener"
"git.faercol.me/faercol/telegram-notifier/notifier/notifier/logger" "git.faercol.me/faercol/telegram-notifier/notifier/logger"
"git.faercol.me/faercol/telegram-notifier/notifier/notifier/sender" "git.faercol.me/faercol/telegram-notifier/notifier/sender"
) )
type cliArgs struct { type cliArgs struct {

View file

@ -4,8 +4,8 @@ import (
"context" "context"
"time" "time"
"git.faercol.me/faercol/telegram-notifier/notifier/notifier/config" "git.faercol.me/faercol/telegram-notifier/notifier/config"
"git.faercol.me/faercol/telegram-notifier/notifier/notifier/logger" "git.faercol.me/faercol/telegram-notifier/notifier/logger"
"github.com/ahugues/go-telegram-api/bot" "github.com/ahugues/go-telegram-api/bot"
"github.com/ahugues/go-telegram-api/structs" "github.com/ahugues/go-telegram-api/structs"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"