Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to use a custom server.xml on Jira Docker image

Hi,

I am trying to build my own Docker Jira image on top of the official Atlassian Image. The main reason to do that is that I want to define a custom keystoreFile in the server.xml, and I can´t find a way to specify that setting as an environment variable to the Atlassian Image. The problem I am having is that apparently my custom server.xml file that I copy to my image gets overwritten by the Atlassian server.xml. The build process completes successfully, but if I log in to the container, the server.xml that I found is the Atlassian one. Is there a way I can avoid that behavior or else specify a keystoreFile to the Atlassian image?

A very simple example of what I am trying is as follows:

´´´

ARG JIRA_VERSION=latest

FROM atlassian/jira-software:${JIRA_VERSION}

COPY server.xml /opt/atlassian/jira/conf

RUN chown jira:jira /opt/atlassian/jira/conf/server.xml

´´´

@Dave Chevellhas helped me in the past with questions like this. Dave, if you have any hint, I would appreciate it.

Thanks in advance!

1 answer

1 accepted

4 votes
Answer accepted

Hi José,

Awesome question, I'm really glad you asked this! I had the same ask come up recently and I have an answer for you that I suspect will be our "official" recommendation to address this.

tl;dr, do this:

COPY server.xml /opt/atlassian/etc/server.xml.j2

Long version:

We use the Jinja2 templating library to translate config from environment variables into server.xml values. We created a server.xml Jinja2 template, which you can find at /opt/atlassian/etc/server.xml.j2, and when you start the container we then use this template to generate the "actual" server.xml file that gets written to /opt/atlassian/jira/conf.

The upshot of this is that you can simply replace the above template with your own file. If you just use a plain server.xml, then when our entrypoint uses it as a template to generate the "real" one it will simply see a template with no merge fields and will copy it to Jira's conf directory as-is. The great thing about this is that it means you can use a regular static file, or you can make your own Jinja2 template and use the same merge fields we do to allow for the best of both worlds: your own customisations, and run-time from-the-environment configuration.

I hope that helps you out and answers your question José!

Cheers,

Dave   

That answers my question, thanks Dave!

@Dave ChevellLooking through that .j2 file, I see where the env variables are injected. Is it possible to inject the keystore path and password using the same method? Can I just specify another env variable and inject it into a j2 file, or is there some method I am not seeing for declaring the env variables that are passed in?

Dave Chevell Atlassian Team Dec 04, 2020

@Joshua Reddish You can add custom placeholders to the .j2 file, mount it into the same location, and then pass equivalent environment variables to write that value.

For example, just now in a local test instance I made a copy of our server.xml.j2 template and added the following line:

<!-- {{this_is_a_variable }} -->

I then started an image, mounted my custom file and passed in my custom variable:

$ docker run -d \
--name jiratest \
-v /path/to/custom/server.xml.j2:/opt/atlassian/etc/server.xml.j2 \
-e THIS_IS_A_VARIABLE=helloworld \
atlassian/jira-software

And here it is:

$ docker exec jiratest cat /opt/atlassian/jira/conf/server.xml | grep '<!--'
<!-- helloworld -->

So yes, adding custom variables to your own template should "just work". Note that I'm using lowercase variable names in the template, even though I pass them in upper-case to Docker. (Uppercase/lowercase translation has to do with some internal machinery having to do with how these templates might be used in other non-Docker automation projects.) You can pass environment variables to Docker in upper or lowercase, but the template should always use lowercase variable names like my example above.

Wow! thanks for the quick response. I cant wait to test this. If it does work, I would suggest adding this to the documentation for the docker image, as it could be very useful for teams trying to work various solutions into their image.

 

Thanks again for your clear and quick response! Hope fully I don't have further questions.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you