Skip to content

Instantly share code, notes, and snippets.

@the0neWhoKnocks
Last active October 4, 2021 20:31
Show Gist options
  • Save the0neWhoKnocks/a6753655ff7caedc788b7bb905d3b961 to your computer and use it in GitHub Desktop.
Save the0neWhoKnocks/a6753655ff7caedc788b7bb905d3b961 to your computer and use it in GitHub Desktop.
Self Hosted Git Server

Self Hosted Git Server


Install on Portainer

  • Couldn't figure out how to use mounts with gogs (there was an odd mix of permissions being used), so you'll have to create some volumes instead.
    • Volumes > Add Volume (x2)
      Name: gogs-backup
      Name: gogs-data
      
  • Container > Add Container
    Name: git
    Registry: DockerHub
    Image: gogs/gogs:0.12.3
    
    • Manual network port publishing
      host: 8007  ->  container: 22    (TCP)
      host: 9007  ->  container: 3000  (TCP)
      
      The host port numbers coincide to what I had open (no specific reason for their values). For example, all my local Apps start at the 9000 range, and I used 8007 just to match what I had for the Server's port (minus a 1000).
    • Advanced Container Settings (section at bottom)
      • Volumes
        container: /home/git/certs (Bind)
        host: /media/nfs_lib/_apps/certs (Writable)
        
        container: /data (Volume)
        host: gogs-data (Writable)
        
        container: /backup (Volume)
        host: gogs-backup (Writable)
        
      • Env
        Name: TZ
        Value: America/Los_Angeles
        
        IMPORTANT: If you don't set your timezone properly before you go through the installation phase, there's no going back. I tried changing it after the fact, and the Server wouldn't boot afterwards. I eventually just started the Container, went into a shell as root, and ran rm -rf /data/* to start fresh. Had to restart the Container after the rm -rf.
      • Restart Policy: Unless Stopped
  • Start the Container
  • Go to http://<SERVER_IP>:9007 (it should land you on the /install page the first time)
    • These are the settings I changed
      Database Type: SQLite3
      Application Name: NoxHub
      Domain: <SERVER_IP>
      SSH Port: 8007
      HTTP Port: 3000  (or you can set it to the forwarded port, and update the above mapping to 'host: 9007  ->  container:  9007')
      Application URL: http://<SERVER_IP>:9007
      Optional Settings > Server and Other Services Settings
        (check) Disable Gravatar Service
        (uncheck) Enable Captcha
      
    • Click the Install button
    • You'll be presented with a login form, choose Create Account
      • Fill in your new account credentials, save them, and log in.
  • Once logged in, click on your profile menu > Your Settings > SSH Keys > Add Key >> Add an existing key, or generate a new one and add it.

Update Config

If you realize that an update is required, you'll need to SSH into the Container since volumes are being used for data.

  • Portainer > Containers > git (or your container name) > Console
    • Connect as root
  • When reading through the docs, they refer to the custom directory a lot. That folder is /data/gogs while in the Container.
    vi /data/gogs/conf/app.ini

Update your Local .ssh config

vim ~/.ssh/config
Host noxhub
  Hostname <SERVER_IP>
  Port 8007
  IdentityFile ~/.ssh/<SSH_FILE>  (not .pub)

In order for the config entry to work, you'll have to go into your cloned repo's .git/config file and update the remote entry.

[remote "origin"]
-  url = ssh://git@<SERVER_IP>:8007/nox/monkey-scripts.git
+  url = ssh://git@noxhub/nox/monkey-scripts.git

You can verify the SSH connection with

ssh -T git@noxhub

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment