Skip to content

Instantly share code, notes, and snippets.

@bobbwal
Last active May 27, 2016 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobbwal/be18773acf8f7155b6a0 to your computer and use it in GitHub Desktop.
Save bobbwal/be18773acf8f7155b6a0 to your computer and use it in GitHub Desktop.
MODX Cloud bitbucket/Github setup

MODX Cloud with Git and Bitbucket (Windows)

  1. Create your Cloud

  2. Set up shell syntax colours (optional)

    Amend /home/.profile as follows:

    Remove the existing PS1 line beginning.

     export PS1=
    

    Add the following code:

     parse_git_branch() {
     	git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
     }
    
     WHITE="\[\033[1;37m\]"
     GREEN="\[\033[32m\]"
     YELLOW="\[\033[0;33m\]"
     CYAN="\[\033[0;36m\]"
     NOCOLOR="\[\033[00m\]"
    
     export PS1="\n$GREEN\u@\h $YELLOW\w$CYAN\$(parse_git_branch)$NOCOLOR\n$ "
    

    Save and upload (makes sure to use unix line endings)

  3. Add SSH alias to you local SSH config: C:\Users\<you>\.ssh\config

     Host cloudhostname
      HostName c8888.paas2.ams.modxcloud.com
      Port 22
      User c8888
    

    You can now connect simply using the alias ssh cloudhostname

  4. Connect and test

  5. Upload .gitignore example

     # Mac OS X specific
     .DS_Store
    
     config.core.php
     ht.access
     index.php
    
     # ignore assets exept css/, js/
     assets/*
     !assets/css/
     !assets/js/
    
     manager/*
     connectors/*
    
     # ignore everything in core/ exept static/
     # to ignore other components add: !core/component/your_component_name
    
     core/*
     !core/components/static/
    
  6. Setup your repository on MODX Cloud

     cd www
     git config --global color.ui auto
     git config --global user.name "Your Name"
     git config --global user.email you@example.com
     git init
     git add -A
     git commit -m "initial commit"
    
  7. Setup your repository on Bitbucket

  8. Add remote on MODX Cloud

     git remote add origin git@bitbucket.org:user/project.git
     git push origin master
    

    Because we haven't setup our SSH keys the push command should return the following:

     Permission denied (publickey).
     fatal: The remote end hung up unexpectedly
    
  9. Create new Bitbucket account

This part is a bit of a faff but is necessary unless you want expose all your repositories to the private key uploaded to MODX Cloud. Creating a new account allows you to grant this account access on a per repository basis. For more information see the following links:

[Additional read-WRITE key per repository basis](https://bitbucket.org/site/master/issues/6887/additional-read-write-key-per-repository)

[Extend deployment keys to allow both: read/write](https://bitbucket.org/site/master/issues/8873/extend-deployment-keys-to-allow-both-read)
1.   Create a new bitbucket account. You must use valid email address so you can validate the account.

2.   Create your SSH key pair [Set up SSH for Git](https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html)

3.   Upload your public key to the newly created bitbucket account

4. Go back to your main bitbucket account which hosts your project repository and go to `Settings > Access management` and search for your newly created bitbucket user. Add the user and grant them write privileges.
  1. Upload SSH private key to your Cloud

    1. Upload your key to /.ssh eg. /.ssh/id_rsa

    2. Set permissions to 400

    3. Create a file named config containing:

       Host bitbucket.org
         IdentityFile ~/.ssh/id_rsa
         User git
      
    4. Upload the file to /.ssh

  2. Upload your public key to Github/Bitbucket

  3. Test with your connection to bitbucket

    `Git push origin master`
    
  4. SFTP Config example

    {
    "type": "sftp",
    
    "save_before_upload": true,
    "upload_on_save": true,
    "sync_down_on_open": true,
    "sync_skip_deletes": false,
    "sync_same_age": false,
    "confirm_downloads": false,
    "confirm_sync": true,
    "confirm_overwrite_newer": true,
    
    "host": "c8888.paas2.ams.modxcloud.com",
    "user": "c8888",
    "password": "password",
    "port": "22",
    
    "remote_path": "/www/",
    "ignore_regexes": [
        "\\.sublime-(project|workspace)", "sftp-config(-alt\\d?)?\\.json",
        "sftp-settings\\.json", "/venv/", "\\.svn/", "\\.hg/", "\\.git/",
        "\\.bzr", "_darcs", "CVS", "\\.DS_Store", "Thumbs\\.db", "desktop\\.ini",
        "manager", "connectors", "core/cache/", "core/config/", "core/docs/",
        "core/error/", "core/export/", "core/import/", "core/lexicon/",
        "core/model/", "core/packages/", "core/xpdo/", "node_modules"
    ],
    "extra_list_connections": 4,
    "connect_timeout": 30,
    "preserve_modification_times": true,
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment