gitblit-org / gitblit

pure java git solution
http://gitblit.com
Apache License 2.0
2.28k stars 670 forks source link

Deploying GitBlit Docker on Azure #1396

Closed farzadrabiee closed 2 years ago

farzadrabiee commented 2 years ago

Hi,

I want to create an instance of GitBlit Container on Azure.

So I created a Container Registry on Azure and pushed the images of GitBlit on it.

After that run the instance of GitBlit and it works.

I need to update the gitblit.properties file, but after restarting the Instance, the gitblit.properties file will be reset and can't store the new data.

The problem is Azure container reset all the data after restarting the Instance.

I tried to change the default address for the settings, it creates the folders (etc, srv and temp) in it but still loads from the default address (var/opt/gitblit)

docker commit --change "ENV GITBLIT_VAR=/settings/" gitblit gitblit:newsettings

Do you have any idea how can fix it?

Thanks

flaix commented 2 years ago

I am not sure I understood what you intend to achieve with the /settings/ folder. Did you attach a dedicated volume to it? I assume you are using the Azure App Service? Containers run in the App Service will not persist any data between runs by default. So if you want to keep data around between container restarts, you will have to configure the App Service to do so.

Your first option is to create a new, personal Docker image from the Gitblit image, with adjusted settings. Your Dockerfiles to create your image would write the settings that you want into the /var/opt/gitblit/etc/gitblit.properties file. This way your custom settings are baked into the image and are used on every run.

But, you are running a Gitblit server, serving Git repositories, and these need to be stored somewhere, too. If you do not configure persistent storage for your Azure App, then all changes in the served Git repositories will be gone after a restart, too. So I suspect that you want to attach some persistent storage to your running container anyhow.

The Gitblit image defines a Docker volume for the path under which Gitblit stores data. See the Readme on Docker Hub for details. So instead of using the default volume, which gets reset, you would want to attach a Azure fileshare as a persistent volume to the Docker container. The target path would be /var/opt/gitblit, if you want to include settings and Git repositories. The Azure documentation has instructions on how to do so.

Another way to enable data persistence is to use the default persistent shared storage of an App. See the chapter "Use persistent shared storage" of the Custom Container for Azure App Service documentation. The problem here is that this uses a fixed path in the container: /home. Which means you have to change the path for Gitblit's file storage form the default /var/opt/gitblit to be /home. I believe you will need to do that by building your own image using the standard Gitblit Docker Dockerfile and set the ENV value for the GITBLIT_VAR in the Dockerfile before the build. It was not defined as an argument, so it cannot simply be set on the command line.

farzadrabiee commented 2 years ago

Thanks you so much @flaix I built a new image of it.

flaix commented 2 years ago

So which option did you choose? The derived image with baked in custom settings or building the normal image with a changed GITBLIT_VAR value? How do you persist the Git repositories in Azure? I am intrigued as to how you run Gitblit on Azure.

farzadrabiee commented 2 years ago

I changed the path of GITBLIT_VAR in the Dockerfile. Also added new settings in that file. Then built a new Docker image.

On Azure, created a Container Registry and pushed the Docker image to it. Also created Azure Storage Account and file share for it. Then created Container Instance and mount the file share to the same path for GITBLIT_VAR.