Initial commit

This commit is contained in:
Tomas Pizarro
2017-11-22 16:53:54 +00:00
commit db36c3beb7
11 changed files with 511 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
FROM bitnami/minideb:jessie
LABEL maintainer "Bitnami <containers@bitnami.com>"
# Install required system packages and dependencies
RUN install_packages ca-certificates wget
RUN wget -nc -P /tmp/bitnami/pkg/cache/ https://downloads.bitnami.com/files/stacksmith/java-1.8.151-0-linux-x64-debian-8.tar.gz && \
echo "f40d337a45217ecc2cc581c44cfffe3df088c0529c78b936168873fe74f8334d /tmp/bitnami/pkg/cache/java-1.8.151-0-linux-x64-debian-8.tar.gz" | sha256sum -c - && \
tar -zxf /tmp/bitnami/pkg/cache/java-1.8.151-0-linux-x64-debian-8.tar.gz -P --transform 's|^[^/]*/files|/opt/bitnami|' --wildcards '*/files' && \
rm -rf /tmp/bitnami/pkg/cache/java-1.8.151-0-linux-x64-debian-8.tar.gz
ENV BITNAMI_APP_NAME="java" \
BITNAMI_IMAGE_VERSION="1.8.151-r0" \
JAVA_HOME="/opt/bitnami/java" \
PATH="/opt/bitnami/java/bin:$PATH"
CMD ["bash"]
+11
View File
@@ -0,0 +1,11 @@
version: '2'
services:
java:
tty: true # Enables debugging capabilities when attached to this container.
image: 'bitnami/java:1.8'
command: ["tail", "-f", "/dev/null"] # To keep the container running
ports:
- 8080:8080
volumes:
- .:/app
+14
View File
@@ -0,0 +1,14 @@
FROM bitnami/java:latest as development
FROM bitnami/minideb:jessie
LABEL maintainer "Bitnami <containers@bitnami.com>"
COPY --from=development /opt/bitnami/java /opt/bitnami/java
ENV BITNAMI_APP_NAME="java" \
BITNAMI_IMAGE_VERSION="1.8.151-r0" \
JAVA_HOME="/opt/bitnami/java" \
PATH="/opt/bitnami/java/bin:$PATH"
CMD ["bash"]
+13
View File
@@ -0,0 +1,13 @@
Copyright (c) 2015-2016 Bitnami
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.
+137
View File
@@ -0,0 +1,137 @@
[![CircleCI](https://circleci.com/gh/bitnami/bitnami-docker-java/tree/master.svg?style=shield)](https://circleci.com/gh/bitnami/bitnami-docker-java/tree/master)
[![Slack](https://img.shields.io/badge/slack-join%20chat%20%E2%86%92-e01563.svg)](http://slack.oss.bitnami.com)
# What is Java?
> Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible.
```bash
$ docker run -it --name java bitnami/java
```
## Docker Compose
```bash
$ curl -sSL https://raw.githubusercontent.com/bitnami/bitnami-docker-java/master/docker-compose.yml > docker-compose.yml
$ docker-compose up -d
```
# Why use Bitnami Images?
* Bitnami closely tracks upstream source changes and promptly publishes new versions of this image using our automated systems.
* With Bitnami images the latest bug fixes and features are available as soon as possible.
* Bitnami containers, virtual machines and cloud images use the same components and configuration approach - making it easy to switch between formats based on your project needs.
* Bitnami images are built on CircleCI and automatically pushed to the Docker Hub.
* All our images are based on [minideb](https://github.com/bitnami/minideb) a minimalist Debian based container image which gives you a small base container image and the familiarity of a leading linux distribution.
# Supported tags and respective `Dockerfile` links
- [`1.8`, `1.8.151-r0`, `latest` (1.8/Dockerfile)](https://github.com/bitnami/bitnami-docker-java/blob/1.8.151-r0/1.8/Dockerfile), [`1.8-prod`, `1.8.151-r0-prod` (1.8/prod/Dockerfile)](https://github.com/bitnami/bitnami-docker-java/blob/1.8.151-r0/1.8/prod/Dockerfile)
Subscribe to project updates by watching the [bitnami/java GitHub repo](https://github.com/bitnami/bitnami-docker-java).
# Get this image
The recommended way to get the Bitnami Java Docker Image is to pull the prebuilt image from the [Docker Hub Registry](https://hub.docker.com/r/bitnami/java).
```bash
$ docker pull bitnami/java:latest
```
To use a specific version, you can pull a versioned tag. You can view the [list of available versions](https://hub.docker.com/r/bitnami/java/tags/) in the Docker Hub Registry.
```bash
$ docker pull bitnami/java:[TAG]
```
If you wish, you can also build the image yourself.
```bash
$ docker build -t bitnami/java https://github.com/bitnami/bitnami-docker-java.git
```
# Running your Java jar or war
The default work directory for the Java image is `/app`. You can mount a folder from your host here that includes your Java jar or war, and run it normally using the `java` command.
```bash
$ docker run -it --name java -v /path/to/app:/app bitnami/java \
java -jar package.jar
```
# Maintenance
## Upgrade this image
Bitnami provides up-to-date versions of Java, including security patches, soon after they are made upstream. We recommend that you follow these steps to upgrade your container.
### Step 1: Get the updated image
```bash
$ docker pull bitnami/java:latest
```
or if you're using Docker Compose, update the value of the image property to `bitnami/java:latest`.
### Step 2: Remove the currently running container
```bash
$ docker rm -v java
```
or using Docker Compose:
```bash
$ docker-compose rm -v java
```
### Step 3: Run the new image
Re-create your container from the new image.
```bash
$ docker run --name java bitnami/java:latest
```
or using Docker Compose:
```bash
$ docker-compose start java
```
# Contributing
We'd love for you to contribute to this Docker image. You can request new features by creating an [issue](https://github.com/bitnami/bitnami-docker-java/issues), or submit a [pull request](https://github.com/bitnami/bitnami-docker-java/pulls) with your contribution.
# Issues
If you encountered a problem running this container, you can file an [issue](https://github.com/bitnami/bitnami-docker-java/issues). For us to provide better support, be sure to include the following information in your issue:
- Host OS and version
- Docker version (`docker version`)
- Output of `docker info`
- Version of this container (`echo $BITNAMI_IMAGE_VERSION` inside the container)
- The command you used to run the container, and any relevant output you saw (masking any sensitive
information)
# Community
Most real time communication happens in the `#containers` channel at [bitnami-oss.slack.com](http://bitnami-oss.slack.com); you can sign up at [slack.oss.bitnami.com](http://slack.oss.bitnami.com).
Discussions are archived at [bitnami-oss.slackarchive.io](https://bitnami-oss.slackarchive.io).
# License
Copyright (c) 2017 Bitnami
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.
+63
View File
@@ -0,0 +1,63 @@
version: 2
jobs:
build:
working_directory: /workdir
docker:
- image: docker:17.06.0-ce-git
environment:
RELEASE_SERIES_LIST: "1.8"
LATEST_STABLE: "1.8"
IMAGE_NAME: java
DOCKER_PROJECT: bitnami
QUAY_PROJECT: bitnami
GCLOUD_PROJECT: bitnami-containers
steps:
- checkout
- setup_remote_docker:
version: 17.06.0-ce
- run:
name: Upgrade system packages (workaround - https://github.com/docker-library/docker/issues/72)
command: |
apk upgrade --no-cache
- run:
name: Install dependencies
command: |
apk add --no-cache curl bash coreutils
- run:
name: Docker info
command: |
docker version
docker info
- restore_cache:
keys:
- cache-{{ .Branch }}
paths:
- /cache/layers.tar
- run:
name: Build docker image
command: |
curl -sL https://raw.githubusercontent.com/bitnami/test-infra/master/circle/docker-image-test.sh | bash -
- save_cache:
key: cache-{{ .Branch }}-{{ epoch }}
paths:
- /cache/layers.tar
- deploy:
name: Publish docker image
command: |
if [ -n "${CIRCLE_TAG}" ]; then
curl -sL https://raw.githubusercontent.com/bitnami/test-infra/master/circle/docker-release-image.sh | bash -
elif [ "${CIRCLE_BRANCH}" == "master" ]; then
curl -sL https://raw.githubusercontent.com/bitnami/test-infra/master/circle/docker-development-image.sh | bash -
fi
workflows:
version: 2
build-and-deploy:
jobs:
- build:
filters:
branches:
only: /.*/
tags:
only: /^[0-9].*-r[0-9]+$/
+11
View File
@@ -0,0 +1,11 @@
version: '2'
services:
java:
tty: true # Enables debugging capabilities when attached to this container.
image: 'bitnami/java:latest'
command: ["tail", "-f", "/dev/null"] # To keep the container running
ports:
- 8080:8080
volumes:
- .:/app
+2
View File
@@ -0,0 +1,2 @@
kubernetes.yml
README.md
+9
View File
@@ -0,0 +1,9 @@
FROM bitnami/java:1.8 as builder
WORKDIR /app
RUN wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war
FROM bitnami/java:1.8-prod
COPY --from=builder /app /app
WORKDIR /app
EXPOSE 8080
CMD ["java", "-jar", "jenkins.war"]
+123
View File
@@ -0,0 +1,123 @@
# Example Application
## TL;DR
```bash
$ kubectl create -f https://raw.githubusercontent.com/bitnami/bitnami-docker-java/master/example/kubernetes.yml
```
## Introduction
This example demostrates the use of the `bitnami/java` image to create a production build of your java application.
For demonstration purposes we will use the [Jenkins](https://jenkins.io/) application, build a image with the tag `bitnami/java-example` and deploy it on a [Kubernetes](https://kubernetes.io) cluster.
## Build and Test
To build a production Docker image of our application we'll use the `bitnami/java:1.8-prod` image, which is a production build of the Bitnami JavaB Image optimized for size.
```Dockerfile
FROM bitnami/java:1.8 as builder
WORKDIR /app
RUN wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war
FROM bitnami/java:1.8-prod
COPY --from=builder /app /app
WORKDIR /app
EXPOSE 8080
CMD ["java", "-jar", "jenkins.war"]
```
The `Dockerfile` consists of two build stages.
* The first stage uses the development image, `bitnami/java:1.8`, to download the application.
* The second stage uses the production image, `bitnami/java:1.8-prod`, and copies over the application. This creates a minimal Docker image that only consists of the application source and the java runtime.
To build the Docker image, execute the command:
```bash
$ docker build -t bitnami/java-example:0.0.1 example/
```
Since the `bitnami/java:1.8-prod` image is optimized for production deployments it does not include any packages that would bloat the image.
```console
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
bitnami/java-example 0.0.1 b6ad4097d596 About an hour ago 339MB
```
You can now launch and test the image locally.
```console
$ docker run -it --rm -p 8080:8080 bitnami/java-example:0.0.1
...
INFO: Jenkins is fully up and running
```
Finally, push the image to the Docker registry
```bash
$ docker push bitnami/java-example:0.0.1
```
## Deployment
The `kubernetes.yml` file from the `example/` folder can be used to deploy our `bitnami/java-example:0.0.1` image to a Kubernetes cluster.
Simply download the Kubernetes manifest and create the Kubernetes resources described in the manifest using the command:
```console
$ kubectl create -f kubernetes.yml
ingress "example-ingress" created
service "example-svc" created
configmap "example-configmap" created
persistentvolumeclaim "example-data-pvc" created
deployment "example-deployment" created
```
From the output of the above command you will notice that we create the following resources:
- [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/)
- [Service](https://kubernetes.io/docs/concepts/services-networking/service/)
- [Volume](https://kubernetes.io/docs/concepts/storage/volumes/)
+ [ConfigMap](https://kubernetes.io/docs/concepts/storage/volumes/#projected)
+ [PersistentVolumeClaim](https://kubernetes.io/docs/concepts/storage/volumes/#persistentvolumeclaim)
- [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
> **Note**
>
> Our example application is stateless and does not store any data or does not require any user configurations. As such we do not need to create the ConfigMap or PersistentVolumeClaim resources. Our kubernetes.yml creates these resources strictly to demostrate how they are defined in the manifest.
## Accessing the application
Typically in production you would access the application via a Ingress controller. Our `kubernetes.yml` already defines a `Ingress` resource. Please refer to the [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/) documentation to learn how to deploy an ingress controller in your cluster.
> **Hint**
>
> https://kubeapps.com/charts/stable/nginx-ingress
The following are alternate ways of accessing the application, typically used during application development and testing.
Since the service `example-svc` is defined to be of type `NodePort`, we can set up port forwarding to access our web application like so:
```bash
$ kubectl port-forward $(kubectl get pods -l app=example -o jsonpath="{ .items[0].metadata.name }") 8080:8080
```
The command forwards the local port `8080` to port `8080` of the Pod container. You can access the application by visiting the http://localhost:8080.
> **Note:**
>
> If your using minikube, you can access the application by simply executing the following command:
>
> ```bash
> $ minikube service example-svc
> ```
## Health Checks
The `kubernetes.yml` manifest defines default probes to check the health of the application. For our application we are simply probing if the application is responsive to queries on the root resource.
You application can define a route, such as the commonly used `/healthz`, that reports the application status and use that route in the health probes.
+112
View File
@@ -0,0 +1,112 @@
apiVersion: v1
items:
- apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
labels:
app: example
annotations:
spec:
rules:
- host: app.example.com
http:
paths:
- path: /
backend:
serviceName: example-svc
servicePort: 80
tls:
- apiVersion: v1
kind: Service
metadata:
name: example-svc
labels:
app: example
spec:
ports:
- name: http
port: 80
targetPort: http
selector:
app: example
type: NodePort
status:
loadBalancer: {}
- apiVersion: v1
kind: ConfigMap
metadata:
name: example-configmap
labels:
app: example
data:
config.js: |-
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: example-data-pvc
annotations: {}
labels:
app: example
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: example-deployment
labels:
app: example
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
app: example
spec:
containers:
- name: example
image: bitnami/java-example:0.0.1
ports:
- containerPort: 8080
name: http
livenessProbe:
httpGet:
path: /login
port: http
httpHeaders:
- name: Host
value: app.example.com
initialDelaySeconds: 15
readinessProbe:
httpGet:
path: /login
port: http
httpHeaders:
- name: Host
value: app.example.com
initialDelaySeconds: 5
resources: {}
volumeMounts:
- mountPath: /app/config.js
name: example-config
subPath: config.js
- mountPath: /app/data
name: example-data
restartPolicy: Always
volumes:
- name: example-config
configMap:
name: example-configmap
- name: example-data
persistentVolumeClaim:
claimName: example-data-pvc
status: {}
kind: List
metadata: {}