Skip to content

Grab container ID using bash sorcery to pass to container_kill_start kill task.#270

Merged
kaushikanurag merged 5 commits intomasterfrom
SAN-3296-buckshot-approach
Jan 19, 2016
Merged

Grab container ID using bash sorcery to pass to container_kill_start kill task.#270
kaushikanurag merged 5 commits intomasterfrom
SAN-3296-buckshot-approach

Conversation

@und1sk0
Copy link
Copy Markdown
Contributor

@und1sk0 und1sk0 commented Jan 15, 2016

Stepping through the changed command:

sudo docker ps | grep -v '^CONTAINER' | awk '{print $1,$2 }' | grep -e 'registry.runnable.com/runnable/navi:reconfigure-newrelic' -v -e : |awk -F' ' '{print $1}'

sudo docker ps

  • self explanitory

grep -v '^CONTAINER'

  • strip the header line

awk '{print $1, $2}'

  • not only do we only care about the first to columns, we are trying to match untagged containers by looking for the absence of a ":" (see next command)

grep -e {{ container_id }} -v -e :

  • match the container_id (registry.runnable.com/<some_service>:<some_branch>) or any untagged container

awk -F' ' '{print $1}'

  • print the container's hash

@anandkumarpatel
Copy link
Copy Markdown

have you tried docker inspect <containerID> on the lost container? that might have better info on something we can grab to tell if it is lost container for that branch. also look into docker ps --format < you can get anything from the output of docker inspect will help reduce the logic in your grep statement

@und1sk0
Copy link
Copy Markdown
Contributor Author

und1sk0 commented Jan 15, 2016

We could but it seems like now we are piling on logic.

Here's a mini-flow, then:

CONTAINER_ID=sudo docker ps | grep {{ container_id }} | awk '{print $1}'
if [ "" != "${CONTAINER_ID}" ] ; then
echo $CONTAINER_ID
else
for ID in sudo docker ps | grep -v '^CONTAINER' | awk '{print $1}' ; do
sudo docker inspect ${ID} | grep -q {{ container_id }}
if [ ${?} ] -eq 0 ; then
OUR_ID=sudo docker inspect ${ID} | awk -F" '{print $4}'
# and in an abundance of caution
CONTAINER_ID="${OUR_ID} ${CONTAINER_ID}"
fi
done
echo $CONTAINER_ID
fi

@und1sk0
Copy link
Copy Markdown
Contributor Author

und1sk0 commented Jan 15, 2016

At this point might as well write a shell script, upload it, and run it...

Comment thread ansible/roles/builder/tasks/main.yml Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is this needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, was for debugging.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

remove comment, documentation is in the name

@und1sk0 und1sk0 changed the title this is a clusterfsck but it works Grab container ID using bash sorcery to pass to container_kill_start kill task. Jan 18, 2016
@anandkumarpatel
Copy link
Copy Markdown

one small nit, but good to go

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

up to your discretion, should this be in /ops/* path?

kaushikanurag added a commit that referenced this pull request Jan 19, 2016
Grab container ID using bash sorcery to pass to container_kill_start kill task.
@kaushikanurag kaushikanurag merged commit cd65ee6 into master Jan 19, 2016
@kaushikanurag kaushikanurag deleted the SAN-3296-buckshot-approach branch January 19, 2016 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants