From a39c3f308792cd17cf9c01fd09c3d02464dac720 Mon Sep 17 00:00:00 2001 From: Melora Hugues Date: Sat, 11 Mar 2023 16:21:03 +0100 Subject: [PATCH] Add dockerfile and CI --- .drone.yml | 90 +++++++++++++++++++++++++++++++++++++++ Dockerfile | 16 +++++++ go.mod => notifier/go.mod | 0 go.sum => notifier/go.sum | 0 notifier/main.go | 8 ++-- notifier/sender/sender.go | 4 +- 6 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 .drone.yml create mode 100644 Dockerfile rename go.mod => notifier/go.mod (100%) rename go.sum => notifier/go.sum (100%) diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..5e8a5b2 --- /dev/null +++ b/.drone.yml @@ -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 + +... \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d1d1252 --- /dev/null +++ b/Dockerfile @@ -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" ] diff --git a/go.mod b/notifier/go.mod similarity index 100% rename from go.mod rename to notifier/go.mod diff --git a/go.sum b/notifier/go.sum similarity index 100% rename from go.sum rename to notifier/go.sum diff --git a/notifier/main.go b/notifier/main.go index 670176d..82d43ac 100644 --- a/notifier/main.go +++ b/notifier/main.go @@ -6,10 +6,10 @@ import ( "os" "os/signal" - "git.faercol.me/faercol/telegram-notifier/notifier/notifier/config" - "git.faercol.me/faercol/telegram-notifier/notifier/notifier/listener" - "git.faercol.me/faercol/telegram-notifier/notifier/notifier/logger" - "git.faercol.me/faercol/telegram-notifier/notifier/notifier/sender" + "git.faercol.me/faercol/telegram-notifier/notifier/config" + "git.faercol.me/faercol/telegram-notifier/notifier/listener" + "git.faercol.me/faercol/telegram-notifier/notifier/logger" + "git.faercol.me/faercol/telegram-notifier/notifier/sender" ) type cliArgs struct { diff --git a/notifier/sender/sender.go b/notifier/sender/sender.go index 371d691..de20d0b 100644 --- a/notifier/sender/sender.go +++ b/notifier/sender/sender.go @@ -4,8 +4,8 @@ import ( "context" "time" - "git.faercol.me/faercol/telegram-notifier/notifier/notifier/config" - "git.faercol.me/faercol/telegram-notifier/notifier/notifier/logger" + "git.faercol.me/faercol/telegram-notifier/notifier/config" + "git.faercol.me/faercol/telegram-notifier/notifier/logger" "github.com/ahugues/go-telegram-api/bot" "github.com/ahugues/go-telegram-api/structs" "github.com/sirupsen/logrus"