You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
3.2 KiB

  1. # Configs of the docker images, you might have specify your own configs here.
  2. DB_TYPE="YOUR_DB_TYPE" # type of database, support 'mysql' and 'postgres'
  3. MEM_TYPE="YOUR_MEM_TYPE" # type of memory database, support 'redis' and 'memcache'
  4. DB_PASSWORD="YOUR_DB_PASSWORD" # The database password.
  5. DB_RUN_NAME="YOUR_DB_RUN_NAME" # The --name option value when run the database image.
  6. MEM_RUN_NAME="YOUR_MEM_RUN_NAME" # The --name option value when run the mem database image.
  7. HOST_PORT="YOUR_HOST_PORT" # The port on host, which will be redirected to the port 3000 inside gogs container.
  8. # apt source, you can select 'nchc'(mirror in Taiwan) or 'aliyun'(best for mainlance China users) according to your network, if you could connect to the official unbunt mirror in a fast speed, just leave it to "".
  9. APT_SOURCE=""
  10. # fail immediately if anything goes wrong
  11. set -e
  12. DOCKER_BIN=$(which docker.io || which docker)
  13. if [ -z "$DOCKER_BIN" ] ; then
  14. echo "Please install docker. You can install docker by running \"wget -qO- https://get.docker.io/ | sh\"."
  15. exit 1
  16. fi
  17. # Replace the database root password in database image Dockerfile.
  18. sed -i "s/THE_DB_PASSWORD/$DB_PASSWORD/g" images/$DB_TYPE/Dockerfile
  19. # Replace the database root password in gogits image deploy.sh file.
  20. sed -i "s/THE_DB_PASSWORD/$DB_PASSWORD/g" images/gogits/deploy.sh
  21. # Replace the apt source in gogits image Dockerfile.
  22. sed -i "s/#$APT_SOURCE#//" images/gogits/Dockerfile
  23. # Uncomment the installation of database lib in gogs Dockerfile
  24. sed -i "s/#$DB_TYPE#//" images/gogits/Dockerfile
  25. # Replace the database type in gogits image deploy.sh file.
  26. sed -i "s/THE_DB_TYPE/$DB_TYPE/g" images/gogits/deploy.sh
  27. if [ $MEM_TYPE != "" ]
  28. then
  29. # Replace the mem configs in deploy.sh
  30. sed -i "s/THE_MEM_TYPE/$MEM_TYPE/g" images/gogits/deploy.sh
  31. # Uncomment the installation of go mem lib
  32. sed -i "s/#$MEM_TYPE#//" images/gogits/Dockerfile
  33. # Add the tags when get gogs
  34. sed -i "s#RUN go get -u -d github.com/gogits/gogs#RUN go get -u -d -tags $MEM_TYPE github.com/gogits/gogs#g" images/gogits/Dockerfile
  35. # Append the tag in gogs build
  36. GOGS_BUILD_LINE=`awk '$0 ~ str{print NR}' str="go build" images/gogits/Dockerfile`
  37. # Append the build tags
  38. sed -i "${GOGS_BUILD_LINE}s/$/ -tags $MEM_TYPE/" images/gogits/Dockerfile
  39. cd images/$MEM_TYPE
  40. $DOCKER_BIN build -t gogits/$MEM_TYPE .
  41. $DOCKER_BIN run -d --name $MEM_RUN_NAME gogits/$MEM_TYPE
  42. MEM_LINK=" --link $MEM_RUN_NAME:mem "
  43. cd ../../
  44. fi
  45. # Build the database image
  46. cd images/$DB_TYPE
  47. $DOCKER_BIN build -t gogits/$DB_TYPE .
  48. #
  49. ## Build the gogits image
  50. cd ../gogits
  51. $DOCKER_BIN build -t gogits/gogs .
  52. #sed -i "s#RUN go get -u -tags $MEM_TYPE github.com/gogits/gogs#RUN go get -u github.com/gogits/gogs#g" Dockerfile
  53. # Remove the appended tags in go build line(if there is any)
  54. sed -i "s/ -tags $MEM_TYPE//" Dockerfile
  55. #
  56. ## Run MySQL image with name
  57. $DOCKER_BIN run -d --name $DB_RUN_NAME gogits/$DB_TYPE
  58. #
  59. ## Run gogits image and link it to the database image
  60. echo "Now we have the $DB_TYPE image(running) and gogs image, use the follow command to start gogs service:"
  61. echo -e "\033[33m $DOCKER_BIN run -i -t --link $DB_RUN_NAME:db $MEM_LINK -p $HOST_PORT:3000 gogits/gogs \033[0m"