Skip to content

Instantly share code, notes, and snippets.

@haani-niyaz
Last active September 3, 2017 05:20
Show Gist options
  • Save haani-niyaz/4e9f208ef6ea555ac62408dcde8a9e90 to your computer and use it in GitHub Desktop.
Save haani-niyaz/4e9f208ef6ea555ac62408dcde8a9e90 to your computer and use it in GitHub Desktop.
Docker commands scratchpad to run bitbucket data center

Network

$ docker network create proteus

Postgresql

$ docker container run --name bitbucket-db --net proteus -e POSTGRES_PASSWORD=jellyfish -d postgres

$ docker container run -it --name postgres-client --net proteus --volumes-from bitbucket-db postgres /bin/bash

psql -h bitbucket-db -p 5432 -U postgres -W
Password for user postgres: 
psql (9.6.4)
Type "help" for help.

postgres=# 
postgres=# 
postgres=# CREATE ROLE bitbucketuser WITH LOGIN PASSWORD 'jellyfish' VALID UNTIL 'infinity';
CREATE ROLE
postgres=# CREATE DATABASE bitbucket WITH ENCODING='UTF8' OWNER=bitbucketuser CONNECTION LIMIT=-1;
CREATE DATABASE


# Add allow connectivity if running from a remote host
vi /var/lib/docker/volumes/7037aca81cc8062d3b0a1b2477471e1f7740071a005a1726b355c35725c76753/_data/pg_hba.conf 
...
host all all 172.18.0.0/16 trust

Bitbucket


# Create a managed volume
$ docker volume create bitbucketVolume

# Start bitbucket server
$ docker run -v bitbucketVolume:/var/atlassian/application-data/bitbucket --env ELASTICSEARCH_ENABLED=false --name="bitbucket-server-01" --net proteus -d -p 7990:7990 -p 7999:7999 atlassian/bitbucket-server:5.0

bitbucket.properties

$ vim /var/atlassian/application-data/bitbucket/shared/bitbucket.properties

#>*******************************************************
#> Migrated to database at jdbc:postgresql://bitbucket-db:5432/bitbucket
#> Updated on 2017-08-22T10:13:47.222Z
#>*******************************************************
jdbc.driver=org.postgresql.Driver
jdbc.url=jdbc:postgresql://bitbucket-db:5432/bitbucket
jdbc.user=bitbucketuser
jdbc.password=jellyfish
plugin.search.elasticsearch.baseurl=http://elasticsearch:9200/
plugin.search.elasticsearch.username=admin
plugin.search.elasticsearch.password=jellyfish

# Use multicast to discover cluster nodes (recommended).
#hazelcast.network.multicast=true

# If your network does not support multicast, you may uncomment the following lines and substitute
# the IP addresses of some or all of your cluster nodes. (Not all of the cluster nodes have to be
# listed here but at least one of them has to be active when a new node joins.) 
hazelcast.network.tcpip=true
hazelcast.network.tcpip.members=<container-ip>:5701,<container-ip>:5701

# The following should uniquely identify your cluster on the LAN. 
hazelcast.group.name=bitbucket-cluster
hazelcast.group.password=jellyfish

Elasticsearch

$ docker volume create elasticsearch-config
$ docker volume create elasticsearch-data


$ docker container run -v elasticsearch-config:/usr/share/elasticsearch/config -d --name elasticsearch --net proteus --env -Etransport.host=0.0.0.0 --env -Ediscovery.zen.minimum_master_nodes=1 elasticsearch:2.3.5

$ vim /var/lib/docker/volumes/elasticsearch-config/_data/elasticsearch.yml 
index.mapper.dynamic: false
action.auto_create_index: false
network.host: 0.0.0.0


$  docker container exec -it --user elasticsearch elasticsearch /bin/bash
$ ./plugin install -b https://maven.atlassian.com/content/groups/public/com/atlassian/elasticsearch/buckler-plugin/0.2.12/buckler-plugin-0.2.12-2.3.5.zip?_ga=2.125723530.1864937751.1503707411-2100088074.1501064668

Automate Plugin Management

https://www.elastic.co/blog/elasticsearch-docker-plugin-management

buckler.yaml

$ vim /usr/share/elasticsearch/config/buckler/buckler.yml
auth.basic.http.enabled: true
auth.basic.username: <username>
auth.basic.password: <password>

elasticsearch.yaml

$ vim /usr/share/elasticsearch/config/elasticsearch.yml
network.host: 0.0.0.0
index.mapper.dynamic: false
action.auto_create_index: false

HAProxy

The following must be done to fix bind errors on ports.


# Fix for cannot bind to socket
 setsebool -P haproxy_connect_any=1

Misc

Start bitbucket with elasticsearch disabled

$ docker run -v bitbucketVolume:/var/atlassian/application-data/bitbucket --env ELASTICSEARCH_ENABLED=false --name="bitbucket-server-01" --net proteus -d -p 7990:7990 -p 7999:7999 atlassian/bitbucket-server:5.0


# ps -ef | grep  '[b]itbucket'
daemon       5     1  0 06:29 ?        00:00:00 bash /opt/atlassian/bitbucket/bin/start-bitbucket.sh --no-search -fg
daemon      28     5  0 06:29 ?        00:00:00 bash /opt/atlassian/bitbucket/bin/_start-webapp.sh run
daemon      35    28 99 06:29 ?        00:02:42 /usr/lib/jvm/java-1.8-openjdk/jre/bin/java -classpath /opt/atlassian/bitbucket/app -Datlassian.standalone=BITBUCKET -Dbitbucket.home=/var/atlassian/application-data/bitbucket -Dbitbucket.install=/opt/atlassian/bitbucket -Xms512m -Xmx1g -XX:+UseG1GC -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -Djava.io.tmpdir=/var/atlassian/application-data/bitbucket/tmp -Djava.library.path=/opt/atlassian/bitbucket/lib/native;/var/atlassian/application-data/bitbucket/lib/native com.atlassian.bitbucket.internal.launcher.BitbucketServerLauncher start --logging.console=true

Compared to default setup

$ docker run -v bitbucketVolume:/var/atlassian/application-data/bitbucket --name="bitbucket-server-01" --net proteus -d -p 7990:7990 -p 7999:7999 atlassian/bitbucket-server:5.0 
 

# ps -ef | grep '[b]itbucket'
daemon       5     1  0 06:32 ?        00:00:00 bash /opt/atlassian/bitbucket/bin/start-bitbucket.sh -fg
daemon      42     1 19 06:32 ?        00:00:07 /usr/lib/jvm/java-1.8-openjdk/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/opt/atlassian/bitbucket/elasticsearch -cp /opt/atlassian/bitbucket/elasticsearch/lib/elasticsearch-2.3.1.jar:/opt/atlassian/bitbucket/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch start -d -p /var/atlassian/application-data/bitbucket/log/search/elasticsearch.pid -Dpath.conf=/var/atlassian/application-data/bitbucket/shared/search -Dpath.logs=/var/atlassian/application-data/bitbucket/log/search -Dpath.data=/var/atlassian/application-data/bitbucket/shared/search/data
daemon      44     5  0 06:32 ?        00:00:00 bash /opt/atlassian/bitbucket/bin/_start-webapp.sh run
daemon      53    44 99 06:32 ?        00:01:01 /usr/lib/jvm/java-1.8-openjdk/jre/bin/java -classpath /opt/atlassian/bitbucket/app -Datlassian.standalone=BITBUCKET -Dbitbucket.home=/var/atlassian/application-data/bitbucket -Dbitbucket.install=/opt/atlassian/bitbucket -Xms512m -Xmx1g -XX:+UseG1GC -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -Djava.io.tmpdir=/var/atlassian/application-data/bitbucket/tmp -Djava.library.path=/opt/atlassian/bitbucket/lib/native;/var/atlassian/application-data/bitbucket/lib/native com.atlassian.bitbucket.internal.launcher.BitbucketServerLauncher start --logging.console=true

Full Example

$ docker container run --name bb-db --net test -e POSTGRES_PASSWORD=jellyfish -d postgres
$ docker container run -it bb-db /bin/bash

# inside container
$ psql -U postgres -W
postgres=# CREATE ROLE bitbucketuser WITH LOGIN PASSWORD 'jellyfish' VALID UNTIL 'infinity';
CREATE ROLE
postgres=# CREATE DATABASE bitbucket WITH ENCODING='UTF8' OWNER=bitbucketuser CONNECTION LIMIT=-1;
CREATE DATABASE

# update pg_hba.conf to allow connectivity


$ docker volume create bb-volume-data
$ docker volume create bb-volume-shared

$ docker run -v bb-volume-shared:/var/atlassian/application-data/bitbucket/shared  -v bb-volume-data:/var/atlassian/application-data/bitbucket -v /root/bitbucket/bitbucket.properties:/var/atlassian/application-data/bitbucket/shared/bitbucket.properties --env ELASTICSEARCH_ENABLED=false --name="bb-01" --net test -d -p 7990:7990 -p 7999:7999 atlassian/bitbucket-server:5.0


$  docker volume create es-volume-config


docker container run -v es-volume-config:/usr/share/elasticsearch/config -v /root/elasticsearch/buckler.yml:/usr/share/elasticsearch/config/buckler/buckler.yml -v /root/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -d --name es --net test --env -Etransport.host=0.0.0.0 --env -Ediscovery.zen.minimum_master_nodes=1 hniyaz/elasticsearch:1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment