Created
          May 10, 2018 15:55 
        
      - 
      
- 
        Save akavel/2decc616d7ab0fd5d3c1824b660d458f to your computer and use it in GitHub Desktop. 
    scripts for upgrading gerrit with docker
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | version: '2' | |
| services: | |
| gerrit_postgres: | |
| image: postgres:9.4 | |
| volumes: | |
| - gerrit_postgres_data:/var/lib/postgresql/data | |
| environment: | |
| - POSTGRES_USER=gerrit | |
| - POSTGRES_PASSWORD=somepassword | |
| - POSTGRES_DB=reviewdb | |
| ports: | |
| - "8822:5432" | |
| volumes: | |
| gerrit_postgres_data: | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | [gerrit] | |
| basePath = git | |
| serverId = d9b45162-4d45-4b25-9936-2b77c21b2656 | |
| canonicalWebUrl = http://localhost:9999/ | |
| [database] | |
| type = postgresql | |
| hostname = gerrit_gerrit_postgres_1 | |
| database = reviewdb | |
| username = gerrit | |
| [index] | |
| type = LUCENE | |
| [auth] | |
| type = OPENID | |
| [sendemail] | |
| smtpServer = localhost | |
| [container] | |
| user = gerrit | |
| javaHome = | |
| [sshd] | |
| listenAddress = *:29418 | |
| [httpd] | |
| listenUrl = http://*:8080/ | |
| [cache] | |
| directory = cache | |
| [plugins] | |
| allowRemoteAdmin = true | |
| [receive] | |
| enableSignedPush = false | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | set -x | |
| set -e | |
| id | |
| SU_GERRIT= | |
| if [ "$(id -u)" == "0" ]; then | |
| if which su-exec; then | |
| SU_GERRIT="su-exec $GERRIT_USER" | |
| else | |
| apk add sudo | |
| SU_GERRIT="sudo -u $GERRIT_USER" | |
| fi | |
| fi | |
| mkdir -p "$GERRIT_SITE" | |
| chown "$GERRIT_USER:$GERRIT_USER" "$GERRIT_SITE" | |
| ( | |
| set -x | |
| cd /gerrit | |
| for dir in ./*; do | |
| if test -d "$dir"; then | |
| rm -rf "$GERRIT_SITE/$dir" | |
| ln -s "/gerrit/$dir" "$GERRIT_SITE/$dir" | |
| fi | |
| done | |
| ) | |
| $SU_GERRIT java -jar "$GERRIT_WAR" init --batch -d "$GERRIT_SITE" | |
| git config -f "$GERRIT_SITE/etc/gerrit.config" container.javaHome "" | |
| cat "$GERRIT_SITE/etc/gerrit.config" | |
| $SU_GERRIT java -jar "$GERRIT_WAR" reindex -d "$GERRIT_SITE" | |
| if [[ $GERRIT_VERSION. == 2.15.* ]]; then | |
| # $SU_GERRIT java -jar "$GERRIT_WAR" migrate-to-note-db -d "$GERRIT_SITE" || true | |
| : | |
| fi | |
| exec $SU_GERRIT "$GERRIT_SITE/bin/gerrit.sh" daemon | |
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| set -e | |
| set -x | |
| PREV="$( (docker inspect -f '{{.Config.Image}}' gerrit) | sed 's/.*://' )" | |
| case "$PREV." in | |
| .) GERRIT_VERSION=2.10.x;; | |
| 2.10.*) GERRIT_VERSION=2.11.10;; | |
| # # TODO(mateuszc): try going straight to 2.13.x | |
| 2.11.*) GERRIT_VERSION=2.12.7;; | |
| 2.12.*) GERRIT_VERSION=2.13.11;; | |
| 2.13.*) GERRIT_VERSION=2.14.8;; | |
| 2.14.*) GERRIT_VERSION=2.15.1;; | |
| *) | |
| echo "error: Don't know how to upgrade further from version $PREV" >&2 | |
| exit 1;; | |
| esac | |
| docker stop gerrit_restore || true | |
| docker stop gerrit || true | |
| docker-compose up -d --build gerrit_postgres | |
| if [[ $GERRIT_VERSION. == 2.10.* ]]; then | |
| # Prepare volume gerrit_index | |
| docker volume rm gerrit_index | |
| docker run \ | |
| --rm \ | |
| -v "gerrit_index:/gerrit/index" \ | |
| ubuntu:16.04 \ | |
| chown 1000:1000 /gerrit/index | |
| fi | |
| docker rm gerrit || true | |
| docker run \ | |
| --name gerrit \ | |
| -v "$PWD/git:/gerrit/git" \ | |
| -v "$PWD/etc:/gerrit/etc" \ | |
| -v "gerrit_index:/gerrit/index" \ | |
| -v "$PWD/init.sh:/gerrit/init.sh:ro" \ | |
| --network gerrit_default \ | |
| -p 9999:8080 \ | |
| -p 29418:29418 \ | |
| openfrontier/gerrit:$GERRIT_VERSION \ | |
| bash /gerrit/init.sh | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment