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.

74 lines
3.1 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. DOCKER_BIN=$(which docker.io || which docker)
  11. if [ -z "$DOCKER_BIN" ] ; then
  12. echo "Please install docker. You can install docker by running \"wget -qO- https://get.docker.io/ | sh\"."
  13. exit 1
  14. fi
  15. # Replace the database root password in database image Dockerfile.
  16. sed -i "s/THE_DB_PASSWORD/$DB_PASSWORD/g" images/$DB_TYPE/Dockerfile
  17. # Replace the database root password in gogits image deploy.sh file.
  18. sed -i "s/THE_DB_PASSWORD/$DB_PASSWORD/g" images/gogits/deploy.sh
  19. # Replace the apt source in gogits image Dockerfile.
  20. sed -i "s/#$APT_SOURCE#//" images/gogits/Dockerfile
  21. # Uncomment the installation of database lib in gogs Dockerfile
  22. sed -i "s/#$DB_TYPE#//" images/gogits/Dockerfile
  23. # Replace the database type in gogits image deploy.sh file.
  24. sed -i "s/THE_DB_TYPE/$DB_TYPE/g" images/gogits/deploy.sh
  25. if [ $MEM_TYPE != "" ]
  26. then
  27. # Replace the mem configs in deploy.sh
  28. sed -i "s/THE_MEM_TYPE/$MEM_TYPE/g" images/gogits/deploy.sh
  29. # Uncomment the installation of go mem lib
  30. sed -i "s/#$MEM_TYPE#//" images/gogits/Dockerfile
  31. # Add the tags when get gogs
  32. 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
  33. # Append the tag in gogs build
  34. GOGS_BUILD_LINE=`awk '$0 ~ str{print NR}' str="go build" images/gogits/Dockerfile`
  35. # Append the build tags
  36. sed -i "${GOGS_BUILD_LINE}s/$/ -tags $MEM_TYPE/" images/gogits/Dockerfile
  37. cd images/$MEM_TYPE
  38. $DOCKER_BIN build -t gogits/$MEM_TYPE .
  39. $DOCKER_BIN run -d --name $MEM_RUN_NAME gogits/$MEM_TYPE
  40. MEM_LINK=" --link $MEM_RUN_NAME:mem "
  41. cd ../../
  42. fi
  43. # Build the database image
  44. cd images/$DB_TYPE
  45. $DOCKER_BIN build -t gogits/$DB_TYPE .
  46. #
  47. ## Build the gogits image
  48. cd ../gogits
  49. $DOCKER_BIN build -t gogits/gogs .
  50. #sed -i "s#RUN go get -u -tags $MEM_TYPE github.com/gogits/gogs#RUN go get -u github.com/gogits/gogs#g" Dockerfile
  51. # Remove the appended tags in go build line(if there is any)
  52. sed -i "s/ -tags $MEM_TYPE//" Dockerfile
  53. #
  54. ## Run MySQL image with name
  55. $DOCKER_BIN run -d --name $DB_RUN_NAME gogits/$DB_TYPE
  56. #
  57. ## Run gogits image and link it to the database image
  58. echo "Now we have the $DB_TYPE image(running) and gogs image, use the follow command to start gogs service:"
  59. echo -e "\033[33m $DOCKER_BIN run -i -t --link $DB_RUN_NAME:db $MEM_LINK -p $HOST_PORT:3000 gogits/gogs \033[0m"