Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to use bashful in a Docker container? #55

Open
anataliocs opened this issue Jul 20, 2018 · 7 comments
Open

Is there a way to use bashful in a Docker container? #55

anataliocs opened this issue Jul 20, 2018 · 7 comments

Comments

@anataliocs
Copy link

Docker image: jboss/base-jdk:8
OS: RHEL

Error:
Line: 193 	File: /home/wagoodman/go/src/github.com/wagoodman/bashful/screen.go 
 exit status 1
&{0xc42000c240} Unable to determine screen width.
@wagoodman
Copy link
Owner

wagoodman commented Jul 20, 2018

I like where your head's at... I haven't tried this, and I can see where there would be problems. I tried running the 00-demo.yml from within your jboss container like so:

# Dockerfile
FROM jboss/base-jdk:8
USER root
RUN yum install -y wget
RUN wget https://github.com/wagoodman/bashful/releases/download/v0.1.1/bashful_0.1.1_linux_amd64.tar.gz
RUN tar -xavf bashful_0.1.1_linux_amd64.tar.gz
RUN chmod +x bashful
RUN mv bashful /usr/local/bin/bashful
USER jboss
COPY bashful/example /opt/jboss/example

where bashful/example is the bashful's repo example dir.

docker build -t test .
docker run  test bashful run example/00-demo.yml

there were issues, but it did run:

Running 
    • Cloning Repos (8 tasks hidden) 
    • Installing dependencies   
      ├─ Installing Oracle client  ....
      ├─ Installing Google chrome  ....
      ├─ Installing MD helper      ...
      └─ Installing Bridgy         ....
    • Building Images           ...
    • Gathering Secrets         ...
    • Building and Migrating    
      ├─ Building app1             ....
      ├─ Building some-app3        ....
      ├─ Building some-lib-4       ....
      ├─ Building some-awesome-app-5 ....
      ├─ Building watcher-app      ....
      └─ Building public-6         ...
      100.00% Complete  Tasks[20/20] Runtime[00:00:09]

Though this wasn't a -ti on the run with a new tty, I think some of the tty defaults were inherited from my terminal session. You might have run this somewhere where there isn't an interactive terminal (say, in a CI/CD pipeline?)...

I think I know in what ways bashful needs to change to support this use-case... but can you give me an example to reproduce the issue you are seeing? A Dockerfile and the command you invoked to get this issue would be ideal.

@anataliocs
Copy link
Author

anataliocs commented Jul 20, 2018

Wow thanks for the prompt response!!! 🙌 @wagoodman

To be more specific I am working on the jboss/keycloak:4.1.0.Final image.

Basically, we want to start-up Keycloak, then run a couple config scripts against it using bashful.

Here is the base docker image jboss/keycloak:4.1.0.Final

https://hub.docker.com/r/jboss/keycloak/~/dockerfile/

FROM jboss/base-jdk:8

ENV KEYCLOAK_VERSION 4.1.0.Final
# Enables signals getting passed from startup script to JVM
# ensuring clean shutdown when container is stopped.
ENV LAUNCH_JBOSS_IN_BACKGROUND 1
ENV PROXY_ADDRESS_FORWARDING false
USER root

RUN yum install -y epel-release git && yum clean all
# The package epel-release has to be present before jq can be installed, so
# this has to be done in a separate line, after installation of epel-release is
# done:
RUN yum install -y jq && yum clean all

USER jboss

ARG GIT_REPO
ARG GIT_BRANCH
ARG KEYCLOAK_DIST=https://downloads.jboss.org/keycloak/$KEYCLOAK_VERSION/keycloak-$KEYCLOAK_VERSION.tar.gz

ADD build-keycloak.sh /opt/jboss/build-keycloak.sh
RUN /opt/jboss/build-keycloak.sh

ADD docker-entrypoint.sh /opt/jboss/

ADD cli /opt/jboss/keycloak/cli
RUN cd /opt/jboss/keycloak && bin/jboss-cli.sh --file=cli/standalone-configuration.cli && rm -rf /opt/jboss/keycloak/standalone/configuration/standalone_xml_history
RUN cd /opt/jboss/keycloak && bin/jboss-cli.sh --file=cli/standalone-ha-configuration.cli && rm -rf /opt/jboss/keycloak/standalone/configuration/standalone_xml_history

ENV JDBC_POSTGRES_VERSION 42.2.2
ENV JDBC_MYSQL_VERSION 5.1.46
ENV JDBC_MARIADB_VERSION 2.2.3

ADD databases/change-database.sh /opt/jboss/keycloak/bin/change-database.sh

RUN mkdir -p /opt/jboss/keycloak/modules/system/layers/base/com/mysql/jdbc/main; cd /opt/jboss/keycloak/modules/system/layers/base/com/mysql/jdbc/main && curl -O http://central.maven.org/maven2/mysql/mysql-connector-java/$JDBC_MYSQL_VERSION/mysql-connector-java-$JDBC_MYSQL_VERSION.jar
ADD databases/mysql/module.xml /opt/jboss/keycloak/modules/system/layers/base/com/mysql/jdbc/main/module.xml

RUN mkdir -p /opt/jboss/keycloak/modules/system/layers/base/org/postgresql/jdbc/main; cd /opt/jboss/keycloak/modules/system/layers/base/org/postgresql/jdbc/main; curl -L http://central.maven.org/maven2/org/postgresql/postgresql/$JDBC_POSTGRES_VERSION/postgresql-$JDBC_POSTGRES_VERSION.jar > postgres-jdbc.jar
ADD databases/postgres/module.xml /opt/jboss/keycloak/modules/system/layers/base/org/postgresql/jdbc/main

RUN mkdir -p /opt/jboss/keycloak/modules/system/layers/base/org/mariadb/jdbc/main; cd /opt/jboss/keycloak/modules/system/layers/base/org/mariadb/jdbc/main; curl -L http://central.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/$JDBC_MARIADB_VERSION/mariadb-java-client-$JDBC_MARIADB_VERSION.jar > mariadb-jdbc.jar
ADD databases/mariadb/module.xml /opt/jboss/keycloak/modules/system/layers/base/org/mariadb/jdbc/main

ENV JBOSS_HOME /opt/jboss/keycloak
ENV LANG en_US.UTF-8

EXPOSE 8080

ENTRYPOINT [ "/opt/jboss/docker-entrypoint.sh" ]

CMD ["-b", "0.0.0.0"]

Here is our docker file, edited for simplicity:

FROM jboss/keycloak:4.1.0.Final

USER root
RUN yum install -y wget && yum clean all
RUN rm -rf /var/cache/yum
RUN wget https://github.com/wagoodman/bashful/releases/download/v0.0.10/bashful_0.0.10_linux_amd64.rpm
RUN rpm -i bashful_0.0.10_linux_amd64.rpm
ADD deps/kc_update_standalone_xml.sh /opt/jboss/keycloak/bin

USER jboss
ADD deps/startup-keycloak.yaml /opt/jboss/keycloak/bin
ENTRYPOINT [ "bashful run /opt/jboss/keycloak/bin/startup-keycloak.yaml" ]

Perhaps it's not the right approach to use bashful as the entrypoint?

So the jist of what we were trying to do was:

Use bashful to startup keycloak using the existing entrypoint:
/opt/jboss/docker-entrypoint.sh

Then run a series of bash scripts such as kc_update_standalone_xml.sh vs the running keycloak instance.

Then we were hoping to run the container using a fairly generic run command similar to this for local dev.

docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -e DB_VENDOR=h2 <orgname>/og-keycloak:development

**UPDATED: ** fixed errors and added more info

@anataliocs
Copy link
Author

Very cool tool btw, I'm going to try to drive adoption at my org :) 🙌

@anataliocs
Copy link
Author

anataliocs commented Jul 20, 2018

Is there a way to pass in a static value for screen width ?

I'm willing to do a PR if you can point me in the right direction.

@wagoodman
Copy link
Owner

wagoodman commented Jul 23, 2018

Thanks for the info! I hadn't realized that it was being used as the entrypoint for a container, which is a different use-case altogether than from what I was imagining (so... here be dragons). For instance, pid 1 within the container (bashful in this case) should handle any signals gracefully and shutdown child processes in a controlled fashion, flush and close fds before forking, and other daemon-like functionalities. However, since all subprocesses are simply bash processes, this simplifies a lot of those requirements nicely (still a few missing though).

Though bashful wasn't meant to do exactly this, I think it can be modified to fit your needs. It seems like the behavior needs to degrade gracefully when tty functions are not available. Currently stty size is used to determine the width, however, I think when this fails bashful should avoid glamorous output (😢) and maintain other functions. There are a few easy patches that can be made such that it will still function under these conditions, but the "real" fix would be to automatically detect this condition and drastically simplify the output (specifically, don't be dependent on screen width).

@anataliocs if you wanted to take a shot at it, I'd start with providing defaults for screen width when this line fails

terminalWidth = terminal.Width
. Then later we can start introducing a dual-mode output mechanism.

@karuppiah7890
Copy link

@wagoodman great work with bashful ! 😁 By the way, is there any idea about creating a Docker image which contains bashful ? 😄 Like if people want to run it in a CI, example Gitlab CI (in my use case), it supports running jobs in a container given a docker image. I was looking for the bashful docker image but couldn't but found this thread which relates to it to some extent. We could have the discussion here or I could create a new issue to discuss about creating a Docker image for bashful.

@wagoodman wagoodman added this to Backlog in Kanban Board via automation Sep 13, 2018
@wagoodman
Copy link
Owner

@karuppiah7890 I think that's a great idea. I added a few issues to the github project to capture this (#58 & #59)... feel free to add information as you see fit.

@github-staff github-staff deleted a comment from knofte Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Kanban Board
  
Backlog
Development

No branches or pull requests

3 participants