Skip to content

Commit

Permalink
refactor(cmd-api-server): migrate container to ubuntu-20.04
Browse files Browse the repository at this point in the history
1. Makes the base image of the API server ubuntu-20.04
2. Upgrades the NodeJS version to v16

Published a version of this commit to ghcr as well, built it
with this command:

DOCKER_BUILDKIT=1 docker build \
  --build-arg NPM_PKG_VERSION=fix-1226 \
  -f ./packages/cactus-cmd-api-server/Dockerfile . \
  -t cas \
  -t cactus-api-server

Tagged as:
ghcr.io/hyperledger/cactus-cmd-api-server:2021-08-15--refactor-1222

Fixes #1222

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Aug 18, 2021
1 parent 8520302 commit dcf4c46
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
54 changes: 34 additions & 20 deletions packages/cactus-cmd-api-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
FROM node:12.20.1-alpine3.12
FROM ubuntu:20.04

ARG NPM_PKG_VERSION=latest

RUN apk update
RUN apk add --no-cache tini
SHELL ["/bin/bash", "-c"]

ARG APP=/usr/src/app/

ENV TZ=Etc/UTC
ENV APP_USER=appuser

RUN addgroup --system $APP_USER
RUN adduser --system $APP_USER -G $APP_USER
RUN mkdir -p ${APP}
# GUI: 3000, API: 4000, gRPC 5000
EXPOSE 3000 4000 5000

RUN mkdir -p "${APP}/log/"
RUN chown -R $APP_USER:$APP_USER "${APP}/log/"
RUN groupadd --gid 1000 appuser \
&& useradd --uid 1000 --gid appuser --shell /bin/bash --create-home ${APP_USER}

RUN apt update && apt install -y curl

RUN mkdir -p "${APP}log/"
RUN chown -R $APP_USER:$APP_USER "${APP}log/"

WORKDIR ${APP}

COPY --chown=${APP_USER}:${APP_USER} ./packages/cactus-cmd-api-server/healthcheck.sh /

RUN chown -R $APP_USER:$APP_USER ${APP}

USER $APP_USER
ARG NPM_PKG_VERSION=latest

ENV TZ=Etc/UTC
ENV NODE_ENV=production

ENV CACTUS_NODE_ID=-
ENV CONSORTIUM_ID=-
ENV KEY_PAIR_PEM=-
Expand All @@ -43,15 +47,25 @@ ENV API_TLS_CLIENT_CA_PEM=-
ENV API_TLS_KEY_PEM=-
ENV API_HOST=0.0.0.0
ENV API_PORT=4000
ENV LOG_LEVEL=TRACE
ENV LOG_LEVEL=INFO

# GUI: 3000, API: 4000
EXPOSE 3000 4000
ENV NVM_DIR /home/${APP_USER}/.nvm
ENV NODE_VERSION 16.3.0
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

USER $APP_USER
# Install nvm with node and npm
RUN mkdir -p ${NVM_DIR}
RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash \
&& source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default \
&& npm install -g npm@7.19.1

RUN npm i @elenaizaguirre/cactus-cmd-api-server@${NPM_PKG_VERSION}
RUN npm install @hyperledger/cactus-cmd-api-server@${NPM_PKG_VERSION} --production

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node", "node_modules/@elenaizaguirre/cactus-cmd-api-server/dist/lib/main/typescript/cmd/cactus-api.js"]
COPY ./packages/cactus-cmd-api-server/docker-entrypoint.sh /usr/local/bin/
HEALTHCHECK --interval=5s --timeout=5s --start-period=1s --retries=30 CMD /healthcheck.sh
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["node_modules/@hyperledger/cactus-cmd-api-server/dist/lib/main/typescript/cmd/cactus-api.js"]
6 changes: 3 additions & 3 deletions packages/cactus-cmd-api-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ if (require.main === module) {
### Complete Example

For a complete example of how to use the API server, read all the code of the
supply chain exmaple's backend package:
supply chain example's backend package:

https://github.com/hyperledger/cactus/tree/main/examples/cactus-example-supply-chain-backend/src/main/typescript

Expand Down Expand Up @@ -219,7 +219,7 @@ DOCKER_BUILDKIT=1 docker build -f ./packages/cactus-cmd-api-server/Dockerfile .

Build with a specific version of the npm package:
```sh
DOCKER_BUILDKIT=1 docker build --build-arg NPM_PKG_VERSION=fix-quorum-contract-types -f ./packages/cactus-cmd-api-server/Dockerfile . -t cas -t cactus-api-server
DOCKER_BUILDKIT=1 docker build --build-arg NPM_PKG_VERSION=main -f ./packages/cactus-cmd-api-server/Dockerfile . -t cas -t cactus-api-server
```

### Running the container image locally
Expand All @@ -239,7 +239,7 @@ Once you've built the container, the following commands should work:
cas
```

- Launch container with plugins of your choice (keychain, consortium connector, etc.)
- Launch container with plugins of your choice (keychain, consortium connector, etc.)

```sh
docker run \
Expand Down
8 changes: 8 additions & 0 deletions packages/cactus-cmd-api-server/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e

if [ "${1#-}" != "${1}" ] || [ -z "$(command -v "${1}")" ]; then
set -- node "$@"
fi

exec "$@"
3 changes: 2 additions & 1 deletion packages/cactus-plugin-ledger-connector-besu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM cactus-api-server:latest

ENV NODE_ENV=production
ARG NPM_PKG_VERSION=latest

RUN npm i @hyperledger/cactus-plugin-ledger-connector-besu@${NPM_PKG_VERSION} --production
RUN npm install @hyperledger/cactus-plugin-ledger-connector-besu@${NPM_PKG_VERSION} --production

0 comments on commit dcf4c46

Please sign in to comment.