Skip to content

Commit

Permalink
Initialize for Stash 3.5.0
Browse files Browse the repository at this point in the history
`launch.sh` is the container entrypoint and will customize and launch Stash.

Replace boilerplate code in the LICENSE and update README.
  • Loading branch information
ahaasler committed Jan 2, 2015
1 parent 00299c5 commit d234d28
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
LICENSE
README.md
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM azul/zulu-openjdk-debian:latest
MAINTAINER Adrian Haasler García <dev@adrianhaasler.com>

# Configuration
ENV STASH_HOME /data/stash
ENV STASH_VERSION 3.5.0

# Install dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
tar \
xmlstarlet

# Create the user that will run the stash instance and his home directory (also make sure that the parent directory exists)
RUN mkdir -p $(dirname $STASH_HOME) \
&& useradd -m -d $STASH_HOME -s /bin/bash -u 782 stash

# Download and install stash in /opt with proper permissions and clean unnecessary files
RUN curl -Lks http://www.atlassian.com/software/stash/downloads/binary/atlassian-stash-$STASH_VERSION.tar.gz -o /tmp/stash.tar.gz \
&& mkdir -p /opt/stash \
&& tar -zxf /tmp/stash.tar.gz --strip=1 -C /opt/stash \
&& chown -R root:root /opt/stash \
&& chown -R 782:root /opt/stash/logs /opt/stash/temp /opt/stash/work \
&& rm /tmp/stash.tar.gz

# Add stash customizer and launcher
COPY launch.sh /launch

# Make stash customizer and launcher executable
RUN chmod +x /launch

# Expose ports
EXPOSE 7990 7999

# Workdir
WORKDIR /opt/stash

# Launch stash
ENTRYPOINT ["/launch"]
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Apache License
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}
Copyright 2015 Adrian Haasler García

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -199,4 +199,3 @@ Apache License
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

115 changes: 112 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,113 @@
docker-stash
============
# docker-stash

Builds a Docker image for Stash
Builds a Docker image for Stash.

## Features

* Runs on a production ready *OpenJDK* 8 - [Zulu](http://www.azulsystems.com/products/zulu "Zulu: Multi-platform Certified OpenJDK") by Azul Systems.
* Ready to be configured with *Nginx* as a reverse proxy (https available).
* Built on top of *Debian* for a minimal image size.

## Usage

```bash
docker run -d -p 7990:7990 -p 7999:7999 ahaasler/stash
```

### Parameters

You can use this parameters to configure your stash instance:

* **-s:** Enables the connector security and sets `https` as connector scheme.
* **-n &lt;proxyName&gt;:** Sets the connector proxy name.
* **-p &lt;proxyPort&gt;:** Sets the connector proxy port.
* **-c &lt;contextPath&gt;:** Sets the context path (do not write the initial /).

This parameters should be given to the entrypoint (passing them after the image):

```bash
docker run -d -p 7990:7990 -p 7999:7999 ahaasler/stash <parameters>
```

> If you want to execute another command instead of launching stash you should overwrite the entrypoint with `--entrypoint <command>` (docker run parameter).
### Nginx as reverse proxy

Lets say you have the following *nginx* configuration for stash:

```
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443;
server_name example.com;
ssl on;
ssl_certificate /path/to/certificate.crt;
ssl_certificate_key /path/to/key.key;
location /stash {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:7990;
proxy_redirect off;
}
}
```

> This is only an example, please secure you *nginx* better.
For that configuration you should run your stash container with:

```bash
docker run -d -p 7990:7990 -p 7999:7999 ahaasler/stash -s -n example.com -p 443 -c stash
```

### Persistent data

The stash home is set to `/data/stash`. If you want to persist your data you should use a data volume for `/data/stash`.

#### Binding a host directory

```bash
docker run -d -p 7990:7990 -p 7999:7999 -v /home/user/stash-data:/data/stash ahaasler/stash
```

Make sure that the stash user (with id 782) has read/write/execute permissions.

If security is important follow the Atlassian recommendation:

> Ensure that only the user running Stash can access the Stash home directory, and that this user has read, write and execute permissions, by setting file system permissions appropriately for your operating system.
#### Using a data-only container

1. Create the data-only container and set proper permissions:

```bash
docker run --name stash-data -v /data/stash busybox true
docker run --rm -it --volumes-from stash-data debian bash
```
The last command will open a *debian* container. Execute this inside that container:
```bash
chown 782:root /data/stash; chmod 770 /data/stash; exit;
```

2. Use it in the stash container:

```bash
docker run --name stash --volumes-from stash-data -d -p 7990:7990 -p 7999:7999 ahaasler/stash
```

## Thanks

* [Docker](https://www.docker.com/ "Docker") for this amazing container engine.
* [Atlassian](https://www.atlassian.com/ "Atlassian") for making great products. Also for their work on [atlassian-docker](https://bitbucket.org/atlassianlabs/atlassian-docker "atlassian-docker repo") which inspired this.
* [Azul Systems](http://www.azulsystems.com/ "Azul Systems") for their *OpenJDK* docker base image.
* And specially to you and the entire community.

## License

This image is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text.
45 changes: 45 additions & 0 deletions launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

# Backup conf/server.xml
cp conf/server.xml conf/server.xml~

while getopts ":sn:p:c:" opt; do
case $opt in
s)
echo "Using security and 'https' as connector scheme"
# Use secure connector
xmlstarlet ed --inplace --delete "/Server/Service/Connector/@secure" conf/server.xml
xmlstarlet ed --inplace --insert "/Server/Service/Connector" --type attr -n secure -v true conf/server.xml
# Use https
xmlstarlet ed --inplace --delete "/Server/Service/Connector/@scheme" conf/server.xml
xmlstarlet ed --inplace --insert "/Server/Service/Connector" --type attr -n scheme -v https conf/server.xml
;;
n)
echo "Using '$OPTARG' as connector proxyName"
# Set connector proxyName
xmlstarlet ed --inplace --delete "/Server/Service/Connector/@proxyName" conf/server.xml
xmlstarlet ed --inplace --insert "/Server/Service/Connector" --type attr -n proxyName -v $OPTARG conf/server.xml
;;
p)
echo "Using '$OPTARG' as connector proxyPort"
# Set connector proxyPort
xmlstarlet ed --inplace --delete "/Server/Service/Connector/@proxyPort" conf/server.xml
xmlstarlet ed --inplace --insert "/Server/Service/Connector" --type attr -n proxyPort -v $OPTARG conf/server.xml
;;
c)
echo "Using '$OPTARG' as context path"
xmlstarlet ed --inplace --delete "/Server/Service/Engine/Host/Context/@path" conf/server.xml
xmlstarlet ed --inplace --insert "/Server/Service/Engine/Host/Context" --type attr -n path -v /$OPTARG conf/server.xml
;;
\?)
echo "Unknown option: -$OPTARG"
;;
:)
echo "-$OPTARG requires an argument"
exit 1
;;
esac
done

# Start stash with stash user
su -m stash -c "bin/start-stash.sh -fg"

0 comments on commit d234d28

Please sign in to comment.