Skip to content

Commit

Permalink
add docker build and publish step
Browse files Browse the repository at this point in the history
  • Loading branch information
mput committed Feb 14, 2024
1 parent bf858f8 commit aee5394
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,30 @@ jobs:
run: |
sudo apt-get install -y ledger
- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
env:
GITHUB_URL: ${{ secrets.GIT_URL }}
GITHUB_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}

- name: set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: build and publish image
if: ${{ github.ref == 'refs/heads/main' }}
env:
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
run: |
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)"
version=${ref}-${GITHUB_SHA:0:7}-$(date -u +%Y-%m-%dT%H:%M:%S)
echo "GITHUB_REF=${GITHUB_REF}, GITHUB_SHA=${GITHUB_SHA}, GIT_BRANCH=${ref}"
echo "version=${version}"
echo ${DOCKER_HUB_TOKEN} | docker login -u ${DOCKER_HUB_USER} --password-stdin
docker buildx build --push \
--build-arg VERSION=${version} \
--platform linux/amd64,linux/arm/v7,linux/arm64 \
-t ${DOCKER_HUB_USER}/teledger:${ref} .
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.22.0-alpine as build


ADD ./ /repo
WORKDIR /repo

ARG VERSION=docker-dev
RUN echo go version: `go version`
RUN echo build version: ${VERSION}

RUN go build -o teledger -ldflags "-X main.version=${VERSION} -s -w" ./app/main.go

FROM golang:1.22.0-alpine

WORKDIR /srv
RUN apk add --no-cache ledger=~3.3.2 && echo ledger: `which ledger`
COPY --from=build /repo/teledger /srv/teledger

CMD ["/srv/teledger"]
10 changes: 10 additions & 0 deletions app/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Opts struct {

URL string `long:"url" env:"URL" required:"true" description:"bot url"`
Debug bool `long:"debug" env:"DEBUG" description:"debug mode"`
Version string
}


Expand All @@ -49,6 +50,7 @@ func (opts *Opts) Execute() error {

dispatcher.AddHandler(handlers.NewCommand("start", start))
dispatcher.AddHandler(handlers.NewCommand("bal", opts.bal))
dispatcher.AddHandler(handlers.NewCommand("version", opts.vesrion))
dispatcher.AddHandler(handlers.NewMessage(nil, message))

// Start receiving updates.
Expand Down Expand Up @@ -80,6 +82,14 @@ func start(b *gotgbot.Bot, ctx *ext.Context) error {
return nil
}

func (opts *Opts) vesrion(b *gotgbot.Bot, ctx *ext.Context) error {
msg := ctx.EffectiveMessage
log.Printf("[INFO] version request. user=%s\n", msg.From.Username)
if _, err := b.SendMessage(msg.Chat.Id, fmt.Sprintf("teledger v:%s", opts.Version), nil); err != nil {
return fmt.Errorf("unable to send message: %w", err)
}
return nil
}

func (opts *Opts) bal(b *gotgbot.Bot, ctx *ext.Context) error {
msg := ctx.EffectiveMessage
Expand Down
1 change: 1 addition & 0 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var version = "dev"
func main() {
fmt.Printf("teledger v:%s\n", version)
opts := bot.Opts{}
opts.Version = version
_, err := flags.Parse(&opts)
if err != nil {
// if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp {
Expand Down

0 comments on commit aee5394

Please sign in to comment.