💾 Archived View for chirale.org › 2020-04-14_6402.gmi captured on 2024-06-16 at 12:19:28. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-05-12)

-=-=-=-=-=-=-

Migrate mercurial code hosting from Bitbucket to your server in 9 steps using docker

By now Atlassian is dropping support to Mercurial on the popular Bitbucket service. Here is a proof of concept to use a Docker container as a separate environment where self-host your code using basic mercurial features without bells and whistles.

Atlassian

using basic mercurial features

To do so, a docker container based on popular and lightweight jdeathe/centos-ssh image will be used. In this example, it’s supposed to use a remote server with docker service up and running.

jdeathe/centos-ssh

Generate public / private pair

Create new keys to authenticate to the new container. Protect it with a password to deploy on external servers safely. In this example, an EdDSA type key is used.

EdDSA

 ssh-keygen -t ed25519 -C "Key for xxx at xxx on xxx" 

Choose keys and passwords

Choose a name for your new container here:

 export SSHCONTAINER=mycodehosting.example.org 

Create a new file named .env with the following content plus a custom:

 SSH_AUTHORIZED_KEYS=*******PASTE PUB KEY here all.sh django2gmi.sh processing README.md wp2gmi.sh SSH_CHROOT_DIRECTORY=%h SSH_INHERIT_ENVIRONMENT=false SSH_PASSWORD_AUTHENTICATION=false SSH_SUDO=ALL=(ALL) ALL SSH_USER=hg SSH_USER_FORCE_SFTP=false SSH_USER_HOME=/home/%u SSH_USER_ID=500:500 SSH_USER_PASSWORD=*******STRONG PASSWORD HERE (without ")*********** SSH_USER_PASSWORD_HASHED=false SSH_USER_PRIVATE_KEY= SSH_USER_SHELL=/bin/bash SYSTEM_TIMEZONE=********YOUR TIMEZONE HERE e.g. Europe/Rome*********** 

This configuration:

Create the centos-ssh container

On the same directory where resides the .env file before, create a new container:

 docker run -d \ --name $SSHCONTAINER \ -p 12120:22 \ --env-file .env \ -v /opt/path/to/some/host/dir:/home \ jdeathe/centos-ssh 

Note: do not use ACL (e.g. setfacl) on /opt/path/to/some/host/dir or .ssh directory will broke (e.g. Bad owner or permissions)

Install mercurial on container

Now on container install mercurial and its dependencies. You can login as root using docker:

 docker exec -it $SSHCONTAINER bash 

or saving this script then chmod a+x it and launch:

 #!/bin/bash set -e docker exec -it -u root $SSHCONTAINER yum install -y python36-devel python36-setuptools gcc docker exec -it -u root $SSHCONTAINER /usr/bin/pip3 install mercurial 

Restart the container:

 docker container restart $SSHCONTAINER 

Then check if mercurial is running for user hg:

 docker exec -it -u hg $SSHCONTAINER hg --version 

Then if container is running smoothly, you can update it to restart always on reboot or on docker service restart:

 docker container update $SSHCONTAINER --restart always 

then check if it’s applied:

 docker container inspect $SSHCONTAINER | grep -B0 -A3 RestartPolicy 

Login to container directly

Now on your local machine you can connect directly to the container using SSH without caring about the host.

By default an iptables rule is created by docker to allow connections from outside. Anyway, you have to specify the port and the user name .ssh/config like this:

 Host mycodehosting.example.org Hostname mycodehosting.example.org User hg Port 12120 PreferredAuthentications publickey IdentityFile /home/chirale/.ssh/id_ed25519_mycodehosting_example_org 

This configuration is useful when you create a subdomain exclusively to host code, then you associate it a port and a username to obtain a mercurial url like this:

ssh://hg@mycodehosting.example.org/test/project

where dir and subdir are directly in /home/hg directory of container, on host /opt/path/to/some/host/dir/hg/test/project. Differently from Bitbucket, you can have how many  directory level you want to host the project.

Create a test repo

Create a test repository inside this container. You can access everywhere with the above ssh configuration using:

 ssh mycodehosting.example.com 

Then you can

 cd repo/ ls mkdir alba cd alba/ hg init hg verify checking changesets checking manifests crosschecking files in changesets and manifests checking files checked 0 changesets with 0 changes to 0 files cat > README.txt Read this CTRL+D hg addremove adding README.md HGUSER=your_username_here hg commit -m "First flight" 

Clone the test repo

Then from everywhere you can clone the repo adding :

 hg clone ssh://mycodehosting.example.org/repo/alba 

You can commit and push now.

If you login to mycodehosting.example.org, no new file was added. You’ve simply to run

 hg update 

to get it. Note that you haven’t to update every time you push new commits on alba to mycodehosting.example.org. Simply all changes are recorded, but not yet reflected on directory structure inside container.

If this is a problem for you, you can automate the update every time hg has a new changeset using for example supervisor service, shipped with centos-ssh.

Compare these:

 parent: 1:9f51cd87d912 tip Second flight branch: default commit: (clean) update: (current) hg summary missing pager command 'less', skipping pager parent: 1:9f51cd87d912 Second flight branch: default commit: (clean) update: 1 new changesets (update) 

The first hasn’t change update: (current), the second has update: 1 new changesets (update).

Migrate the code from Bitbucket to self-host

From the container, logged as hg user, import temporary your key to download the repository from old bitbucket location following Bitbucket docs, then:

Bitbucket docs

 cd ~ mkdir typeofproject cd typeofproject hg clone ssh://hg@bitbucket.org/yourbbuser/youroldbbrepo 

Then you can alter the directory as you like:

Remember to temporary store on the container the ssh keys and config to access to Bitbucket if any (permission should be 600). You can remove these keys when migration is done.

After a test clone you can drop the Bitbucket repo.

Find your flow

With a self-hosted solution you have to maintain the service. This is a relatively simple solution to set up and maintain.

If you are comfortable with old Bitbucket commit web display, you can use PyCharm to see a nice commit tree like this:

PyCharm

https://chirale.wordpress.com/wp-content/uploads/2020/04/pycharm-commit-tree.png?w=300

Tested on release 1 with centos:

https://web.archive.org/web/20200414000000*/https://bitbucket.org/blog/sunsetting-mercurial-support-in-bitbucket

https://web.archive.org/web/20200414000000*/https://www.mercurial-scm.org/wiki/QuickStart#Network_support

https://web.archive.org/web/20200414000000*/https://github.com/jdeathe/centos-ssh

https://web.archive.org/web/20200414000000*/https://en.wikipedia.org/wiki/EdDSA

https://web.archive.org/web/20200414000000*/https://github.com/docker/for-linux/issues/690

https://web.archive.org/web/20200414000000*/https://blog.viktorpetersson.com/2014/11/03/the-dangers-of-ufw-docker.html

https://web.archive.org/web/20200414000000*/https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html

https://web.archive.org/web/20200414000000*/https://www.jetbrains.com/pycharm/

https://web.archive.org/web/20200414000000*/http://chirale.org/?attachment_id=6490

https://web.archive.org/web/20200414000000*/https://chirale.wordpress.com/2020/04/14/migrate-mercurial-code-hosting-from-bitbucket-to-your-server-in-9-steps-using-docker/pycharm-commit-tree/