Skip to content

Commit

Permalink
[#2] productization: build & deploy
Browse files Browse the repository at this point in the history
Scripts to build & deploy the api-server onto a cluster.
The deployment uses a route to expose the port 9443 of the pod running
the express server so that any client can connect to it.
  • Loading branch information
lavocatt committed Jul 16, 2024
1 parent c9b3fda commit 48ec238
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 1 deletion.
68 changes: 68 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
FROM registry.access.redhat.com/ubi8/nodejs-20:latest AS BUILD_IMAGE

### BEGIN REMOTE SOURCE
# Use the COPY instruction only inside the REMOTE SOURCE block
# Use the COPY instruction only to copy files to the container path $REMOTE_SOURCES_DIR/activemq-artemis-jolokia-api-server/app
ARG REMOTE_SOURCES_DIR=/tmp/remote_source
RUN mkdir -p $REMOTE_SOURCES_DIR/activemq-artemis-jolokia-api-server/app
WORKDIR $REMOTE_SOURCES_DIR/activemq-artemis-jolokia-api-server/app
# Copy package.json and yarn.lock to the container
COPY package.json package.json
COPY yarn.lock yarn.lock
ADD . $REMOTE_SOURCES_DIR/activemq-artemis-jolokia-api-server/app
RUN command -v yarn || npm i -g yarn
### END REMOTE SOURCE

USER root

## Set directory
RUN mkdir -p /usr/src/
RUN cp -r $REMOTE_SOURCES_DIR/activemq-artemis-jolokia-api-server/app /usr/src/
WORKDIR /usr/src/app

## Install dependencies
RUN yarn install --network-timeout 1000000

## Build application
RUN yarn build

FROM registry.access.redhat.com/ubi8/nodejs-20-minimal:latest

USER root

WORKDIR /app

COPY --from=BUILD_IMAGE /usr/src/app/dist /usr/share/amq-spp/dist
COPY --from=BUILD_IMAGE /usr/src/app/.env /usr/share/amq-spp/.env

WORKDIR /usr/share/amq-spp

RUN npm install connect \
cors \
express \
express-openapi-validator \
swagger-routes-express \
typescript \
validator \
yaml \
base-64 \
jsonwebtoken \
dotenv \
express-rate-limit \
node-fetch@2 \
@peculiar/x509

RUN echo "node /usr/share/amq-spp/dist/app.js" > run.sh
RUN chmod +x run.sh

USER 1001

ENV NODE_ENV=production

CMD ["node", "dist/app.js"]

## Labels
LABEL name="artemiscloud/activemq-artemis-jolokia-api-server"
LABEL description="ActiveMQ Artemis Jolokia api-server"
LABEL maintainer="Roderick Kieley <[email protected]>"
LABEL version="0.1.0"
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,37 @@ yarn run build-api-doc

## Production build

To be defined.
1. Build the image:
```sh
docker build -t quay.io/artemiscloud/activemq-artemis-self-provisioning-plugin:latest .
```
2. Push the image to image registry:
```sh
docker push quay.io/artemiscloud/activemq-artemis-self-provisioning-plugin:latest
```

### deploy the service

```sh
./deploy.sh [-i <image> -n]
```

The optional `-i <image>` (or `--image <image>`) argument allows you to pass in
the plugin image. If not specified the default
`quay.io/artemiscloud/activemq-artemis-jolokia-api-server:latest` is
deployed. for example:

```sh
./deploy.sh -i quay.io/<repo-username>/activemq-artemis-jolokia-api-server:1.0.1
```

The `deploy.sh` script uses `oc kustomize` (built-in
[kustomize](https://github.com/kubernetes-sigs/kustomize)) command to configure
and deploy the plugin using resources and patches defined under ./deploy
directory.

To undeploy, run

```sh
./undeploy.sh
```
39 changes: 39 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env sh

DEFAULT_IMAGE="quay.io/artemiscloud/activemq-artemis-jolokia-api-server:latest"
PLUGIN_IMAGE=${DEFAULT_IMAGE}

SCRIPT_NAME=$(basename "$0")

function printUsage() {
echo "${SCRIPT_NAME}: Deploying to openshift"
echo "Usage:"
echo " ./${SCRIPT_NAME} -i|--image <image url>"
echo "Options: "
echo " -i|--image Specify the plugin image to deploy. (default is ${DEFAULT_IMAGE})"
echo " -h|--help Print this message."
}

while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
printUsage
exit 0
;;
-i|--image)
PLUGIN_IMAGE="$2"
shift
shift
;;
-*|--*)
echo "Unknown option $1"
printUsage
exit 1
;;
*)
;;
esac
done

echo "deploying using image: ${PLUGIN_IMAGE}"
oc kustomize deploy | sed "s|image: .*|image: ${PLUGIN_IMAGE}|" | oc apply -f -
52 changes: 52 additions & 0 deletions deploy/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: activemq-artemis-jolokia-api-server
name: activemq-artemis-jolokia-api-server
labels:
app: activemq-artemis-jolokia-api-server
spec:
replicas: 1
selector:
matchLabels:
app: activemq-artemis-jolokia-api-server
template:
metadata:
labels:
app: activemq-artemis-jolokia-api-server
spec:
containers:
- name: activemq-artemis-jolokia-api-server
image: quay.io/artemiscloud/activemq-artemis-jolokia-api-server:latest
ports:
- containerPort: 9443
protocol: TCP
args: ['dist/app.js']
command:
- node
imagePullPolicy: Always
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
resources:
requests:
cpu: 10m
memory: 50Mi
volumeMounts:
- name: plugin-serving-cert
readOnly: true
mountPath: /var/serving-cert
volumes:
- name: plugin-serving-cert
secret:
secretName: plugin-serving-cert
defaultMode: 420
restartPolicy: Always
dnsPolicy: ClusterFirst
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
6 changes: 6 additions & 0 deletions deploy/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace: activemq-artemis-jolokia-api-server

resources:
- namespace.yaml
- deployment.yaml
- service.yaml
4 changes: 4 additions & 0 deletions deploy/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: activemq-artemis-jolokia-api-server
22 changes: 22 additions & 0 deletions deploy/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v1
kind: Service
metadata:
annotations:
service.beta.openshift.io/serving-cert-secret-name: plugin-serving-cert
name: activemq-artemis-jolokia-api-server
namespace: activemq-artemis-jolokia-api-server
labels:
app: activemq-artemis-jolokia-api-server
app.kubernetes.io/component: activemq-artemis-jolokia-api-server
app.kubernetes.io/instance: activemq-artemis-jolokia-api-server
app.kubernetes.io/part-of: activemq-artemis-jolokia-api-server
spec:
ports:
- name: 443-tcp
protocol: TCP
port: 9443
targetPort: 9443
selector:
app: activemq-artemis-jolokia-api-server
type: ClusterIP
sessionAffinity: None
3 changes: 3 additions & 0 deletions undeploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

oc kustomize deploy | oc delete -f -

0 comments on commit 48ec238

Please sign in to comment.