James111
James111

Reputation: 15903

How can I force cancel dockerbuild using bash a command?

The reason why I'm asking is because we're using AWS codebuild & I need to do DB migrations. If a DB migration breaks, I want to cancel the codebuild & rollback the migration which was just made. I've got this part working, all I need to do now is cancel the dockerbuild mid way. How can I do this?

This is my .sh file with the knex migration commands:

#!/bin/bash
echo "running"
function mytest {
    "$@"
    local status=$?
    if [ $status -ne 0 ]; then
        knex migrate:rollback 
      echo "Rolling back knex migrate $1" >&2
      exit
    fi
    return $status
}

mytest knex migrate:latest 

Running exit will not cancel/break the docker build.

My Dockerfile (just incase):

FROM node:6.2.0

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install

# Bundle app source
COPY . /usr/src/app
RUN chmod +x /usr/src/app/migrate.sh
RUN /usr/src/app/migrate.sh


EXPOSE 8080

CMD npm run build && npm start

Upvotes: 2

Views: 502

Answers (1)

VonC
VonC

Reputation: 1327004

Running exit will not cancel/break the docker build.

running exit 1 should

Docker should respond to the error codes returned by the RUN shell scripts in said Dockerfile.

Upvotes: 3

Related Questions