progressbar icon indicating copy to clipboard operation
progressbar copied to clipboard

Progressbar in docker container

Open Bird87ZA opened this issue 5 years ago • 5 comments

Not so much a bug as a request to see if someone can assist.

I have the progress bar in my app. If I run my app using go run main.go it works fine. However, if I run docker-container up --build it doesn't show the progress bar until it reaches 100%.

Does anyone know how what I should change to make it show the progress bar?

Bird87ZA avatar May 11 '20 12:05 Bird87ZA

@Bird87ZA Do you have a minimal example you can share?

schollz avatar May 11 '20 13:05 schollz

This is how my docker is set up:

#docker-compose.yml
version: "3.4"

services:
  app:
    build:
      context: .
      target: app
    ports:
      - 8080:8080
    env_file:
      - .env
#Dockerfile
### Base
FROM golang AS base

WORKDIR /app

ENV CGO_ENABLED=0 \
    GOOS=linux \
    GOARCH=amd64

### Builder
FROM base as builder

COPY . .

RUN go build -mod=vendor

### App
FROM gcr.io/distroless/static as app
COPY --from=builder /app/so-kafka-migration-tool /so-kafka-migration-tool

ENTRYPOINT ["/so-kafka-migration-tool"]

Then this is my main.go file:

package main

import (
	"github.com/k0kubun/go-ansi"
	"github.com/schollz/progressbar/v3"
	"time"
)

func main() {
	bar := progressbar.NewOptions(
		100,
		progressbar.OptionSetWidth(30),
		progressbar.OptionSetWriter(ansi.NewAnsiStdout()),
		progressbar.OptionEnableColorCodes(true),
		progressbar.OptionSetDescription("[blue]Writing To SO Kafka...[reset]"),
		progressbar.OptionSetTheme(progressbar.Theme{
			Saucer:        "[green]=[reset]",
			SaucerHead:    "[green]>[reset]",
			SaucerPadding: " ",
			BarStart:      "[",
			BarEnd:        "]",
		}),
	)
	for i := 0; i < 100; i++ {
		bar.Add(1)
		time.Sleep(40 * time.Millisecond)
	}
}

If I run it with go run main.go it works perfectly.

If I run it with docker-compose up --build it doesn't show the progress bar until it's 100%.

Bird87ZA avatar May 11 '20 13:05 Bird87ZA

It might be a docker-compose thing. Have you tried in just docker, using the TTY flag?

schollz avatar May 12 '20 16:05 schollz

I couldn't get your example to work, but this works fine:

# Dockerfile
FROM golang AS builder

WORKDIR /app

COPY . .

RUN go mod init test.com/m1
RUN go build -v

FROM alpine:latest
COPY --from=builder /app/m1 /m1
ENTRYPOINT ["/m1"]

Using your main.go in the same folder:

docker build -t test1 .
docker run test`

and it shows the progress.

schollz avatar May 12 '20 16:05 schollz