gocha124の日記

ごちゃごちゃ書きます

Gitと連携してdocker build

cd ~/build_httpd
git init
echo ".git" > .dockerignore
vi .git/hooks/pre-commit
chmod u+x .git/hooks/pre-commit

~/build_httpd/.git/hooks/pre-commit

#!/bin/bash

../build_info

if [[ -z $DOCKER_REPO || -z $DOCKER_TAG ]]; then
  echo "you need to set ¥$DOCKER_REPO and ¥$DOCKER_TAG in build_info."
  exit 1
fi

if docker images $DOCKER_REPO | awk '{print $2}' | grep -q $DOCKER_TAG; then
  echo "Image $DOCKER_REPO:$DOCKER_TAG already exists."
  echo "Please specify a different tag in build_info."
  exit 1
fi

echo "Build an image $DOCKER_REPO:$DOCKER_TAG..."
docker build -t $DOCKER_REPO:$DOCKER_TAG .
rc=$?

if [[ $rc -eq 0 ]]; then
  echo "Build succeeded. Your change will be committed."
  echo ""
  exit 0
else
  echo "Build failed. Your change won't be committed."
  echo ""
  exit 1
fi

~/build_httpd/build_info

DOCKER_REPO=txcdb738/httpd
DOCKER_TAG=ver1.2