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.

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