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

Make CLI wait for init to complete #225

Merged
merged 6 commits into from
Oct 18, 2022
Merged

Make CLI wait for init to complete #225

merged 6 commits into from
Oct 18, 2022

Conversation

thomas-gerber
Copy link
Contributor

@thomas-gerber thomas-gerber commented Oct 15, 2022

Description

This change also detaches on UP, and then follows the faros init log. Following that log ensures that the CLI waits for the completion of the init.

Note that purposefully use grep instead of jq to avoid making the latter a pre-requisite to run start.sh.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Have you checked to there aren't other open Pull Requests for the same update/change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you successfully run tests with your changes locally?

This change also detaches on UP, and then follows the faros init log.
Following that log ensures that the CLI waits for the completion of the init.
start.sh Outdated
fi

if ((run_cli)); then
faros_init_exit=$(docker-compose ps faros-init --format json | grep -Eo '"ExitCode"[^,]*' | grep -Eo '[^:]*$')
if [ "$faros_init_exit" != 0 ]; then
printf "an error occured during startup, exiting... \n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. "An"
  2. Let's note that the error was during the startup of the faros init process + advise what to look for

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to be clear, they would already know what to look for because it is a few lines above in the faros init log that is followed

start.sh Outdated
@@ -60,12 +59,17 @@ main() {
if [[ $(uname -m 2> /dev/null) == 'arm64' ]]; then
# Use Metabase images built for Apple M1
METABASE_IMAGE="farosai.docker.scarf.sh/farosai/metabase-m1" \
docker-compose up --build --remove-orphans $detach
docker-compose up --build --remove-orphans --detach && docker-compose logs --follow faros-init
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What happens with logs from other containers?
  2. I think there is a better way of doing this. WDYT? @willmarks @cjwooo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those logs still exist; you can access them from Docker Desktop or docker-compose logs.
I like this approach because the current behavior is just to follow all logs at once and require you to keep the terminal open, which is not very friendly. Just following the Faros init is better IMO, and has the added benefit of returning once that container exists, which we can then use to go to the next command (CLI) without race conditions.

start.sh Outdated
fi

if ((run_cli)); then
faros_init_exit=$(docker-compose ps faros-init --format json | grep -Eo '"ExitCode"[^,]*' | grep -Eo '[^:]*$')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a good idea, but since I still want to follow the faros init log, I cannot use wait after because that container has already exited. Hence ps and grep.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter that the container has already exited. It'll just give you the exit code immediately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw I'm okay with either but would love to minimize the grep dark magic 😄

This will harmonize the container name scheme separator to '-'.
This matters because Docker Desktop has a setting that automatically
converts V1 calls to V2 calls, which can be problematic if we use
commands relying on container names.

We also switch to using `docker wait` instead of `ps` to get exit code.
start.sh Outdated
@@ -19,15 +19,14 @@ email_prompt() {
}

function setDefaults() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets delete this unused function

@@ -55,17 +50,22 @@ main() {
# Ensure we're using the latest faros-init image
export FAROS_INIT_IMAGE=farosai.docker.scarf.sh/farosai/faros-ce-init:latest

docker-compose pull faros-init
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ypc-faros can you confirm removing that is ok? I don't know why it was in in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed this. We actually need it to make sure we pull the latest faros init image.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomas-gerber thomas-gerber merged commit 76acff1 into main Oct 18, 2022
@thomas-gerber thomas-gerber deleted the cli_after_init branch October 18, 2022 22:40
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants