Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rest): add docker image #257

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .github/actions/setup-indy-pool/action.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/actions/setup-libindy/action.yml

This file was deleted.

29 changes: 12 additions & 17 deletions .github/workflows/continuous-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,29 @@ on:
push:
tags:
- rest-v*
pull_request:
branches:
- main

env:
IMAGE_NAME: ghcr.io/openwallet-foundation/credo-rest

jobs:
release-rest-docker-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# Initiate release process if release was created
- name: Checkout credo-ts-ext
uses: actions/checkout@v4

# Some packages need indy-sdk for node as part of yarn install
- name: Setup Libindy
uses: ./.github/actions/setup-libindy

- name: Setup node v18
uses: actions/setup-node@v4
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
node-version: 18
registry-url: 'https://registry.npmjs.org/'
cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build rest package
run: yarn workspace @credo-ts/rest build
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
Expand All @@ -42,7 +37,7 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./packages/rest
context: .
file: ./packages/rest/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
25 changes: 2 additions & 23 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ on:
push:
branches: [main, 'credo-**']

env:
TEST_AGENT_PUBLIC_DID_SEED: 000000000000000000000000Trustee9
GENESIS_TXN_PATH: network/genesis/local-genesis.txn

# Make sure we're not running multiple release steps at the same time as this can give issues with determining the next npm version to release.
# Ideally we only add this to the 'release' job so it doesn't limit PR runs, but github can't guarantee the job order in that case:
# "When concurrency is specified at the job level, order is not guaranteed for jobs or runs that queue within 5 minutes of each other."
Expand Down Expand Up @@ -81,14 +77,6 @@ jobs:
- name: Checkout credo-ts-ext
uses: actions/checkout@v4

# setup dependencies
- name: Setup Libindy
uses: ./.github/actions/setup-libindy
- name: Setup Indy Pool
uses: ./.github/actions/setup-indy-pool
with:
seed: ${TEST_AGENT_PUBLIC_DID_SEED}

- name: Setup node ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
Expand All @@ -99,17 +87,8 @@ jobs:
- name: Install dependencies
run: yarn install

- name: Run tests for Push notifications
run: TEST_AGENT_PUBLIC_DID_SEED=${TEST_AGENT_PUBLIC_DID_SEED} GENESIS_TXN_PATH=${GENESIS_TXN_PATH} yarn test push-notifications --coverage

- name: Run tests for React hooks
run: TEST_AGENT_PUBLIC_DID_SEED=${TEST_AGENT_PUBLIC_DID_SEED} GENESIS_TXN_PATH=${GENESIS_TXN_PATH} yarn test react-hooks --coverage

- name: Run tests for Redux store
run: TEST_AGENT_PUBLIC_DID_SEED=${TEST_AGENT_PUBLIC_DID_SEED} GENESIS_TXN_PATH=${GENESIS_TXN_PATH} yarn test redux-store --coverage

- name: Run tests for Rest
run: TEST_AGENT_PUBLIC_DID_SEED=${TEST_AGENT_PUBLIC_DID_SEED} GENESIS_TXN_PATH=${GENESIS_TXN_PATH} yarn test rest --coverage
- name: Run tests
run: yarn test --coverage

- uses: codecov/codecov-action@v1
if: always()
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ If you're just getting started the [Credo repo](https://github.com/openwallet-fo

All packages are placed in the [`packages/`](./packages) directory.

| Package | Version | Description |
| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| [`@credo-ts/rest`](https://www.npmjs.com/package/@credo-ts/rest) | ![@credo-ts/rest version](https://img.shields.io/npm/v/@credo-ts/rest) | REST endpoint wrapper for using your agent over HTTP |
| [`@credo-ts/react-hooks`](https://www.npmjs.com/package/@credo-ts/react-hooks) | ![@credo-ts/react-hooks version](https://img.shields.io/npm/v/@credo-ts/react-hooks) | React Hooks for data handling and agent interaction |
| [`@credo-ts/redux-store`](https://www.npmjs.com/package/@credo-ts/redux-store) | ![@credo-ts/redux-store version](https://img.shields.io/npm/v/@credo-ts/redux-store) | Redux Toolkit wrapper around Credo |
| [`@credo-ts/push-notifications`](https://www.npmjs.com/package/@credo-ts/push-notifications) | ![@credo-ts/push-notifications version](https://img.shields.io/npm/v/@credo-ts/push-notifications) | Push notification plugin for Credo |
| [`@credo-ts/transport-ble`](https://www.npmjs.com/package/@credo-ts/transport-ble) | ![@credo-ts/transport-ble version](https://img.shields.io/npm/v/@credo-ts/transport-ble) | Bluetooth Low Energy transport for Credo |
| Package | Version | Description |
| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| [`@credo-ts/rest`](https://www.npmjs.com/package/@credo-ts/rest) | ![@credo-ts/rest version](https://img.shields.io/npm/v/@credo-ts/rest) | Rest API for using Credo over HTTP |
| [`@credo-ts/react-hooks`](https://www.npmjs.com/package/@credo-ts/react-hooks) | ![@credo-ts/react-hooks version](https://img.shields.io/npm/v/@credo-ts/react-hooks) | React Hooks for data handling and agent interaction |
| [`@credo-ts/redux-store`](https://www.npmjs.com/package/@credo-ts/redux-store) | ![@credo-ts/redux-store version](https://img.shields.io/npm/v/@credo-ts/redux-store) | Redux Toolkit wrapper around Credo |
| [`@credo-ts/push-notifications`](https://www.npmjs.com/package/@credo-ts/push-notifications) | ![@credo-ts/push-notifications version](https://img.shields.io/npm/v/@credo-ts/push-notifications) | Push notification plugin for Credo |
| [`@credo-ts/transport-ble`](https://www.npmjs.com/package/@credo-ts/transport-ble) | ![@credo-ts/transport-ble version](https://img.shields.io/npm/v/@credo-ts/transport-ble) | Bluetooth Low Energy transport for Credo |

## Contributing

Expand Down
45 changes: 4 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,9 @@
"private": true,
"license": "Apache-2.0",
"description": "Monorepo containing extensions for Credo",
"workspaces": {
"packages": [
"packages/*"
],
"nohoist": [
"@credo-ts/*",
"**/@credo-ts/*",
"**/@credo-ts/*/**",
"@credo-ts/*/**",
"@aries-framework/*",
"**/@aries-framework/*",
"**/@aries-framework/*/**",
"@aries-framework/*/**",
"@hyperledger/*",
"**/@hyperledger/*",
"**/@hyperledger/*/**",
"@hyperledger/*/**",
"tsyringe",
"**/tsyringe",
"**/tsyringe/**",
"tsyringe/**",
"node-fetch",
"**/node-fetch",
"**/node-fetch/**",
"node-fetch/**",
"reflect-metadata",
"**/reflect-metadata",
"**/reflect-metadata/**",
"reflect-metadata/**",
"class-validator",
"**/class-validator",
"**/class-validator/**",
"class-validator/**",
"class-transformer",
"**/class-transformer",
"**/class-transformer/**",
"class-transformer/**"
]
},
"workspaces": [
"packages/*"
],
"repository": {
"url": "https://github.com/openwallet-foundation/credo-ts-ext",
"type": "git"
Expand Down Expand Up @@ -78,10 +42,9 @@
"rimraf": "^5.0.5"
},
"engines": {
"node": ">= 16"
"node": ">= 18"
},
"resolutions": {
"@types/indy-sdk": "1.16.9",
"@jest/types": "^29.5.0",
"@types/node": "^18.0.0"
}
Expand Down
63 changes: 36 additions & 27 deletions packages/rest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
FROM ubuntu:18.04 as base
FROM node:20 as all-dependencies

ENV DEBIAN_FRONTEND noninteractive
WORKDIR /all-dependencies

RUN apt-get update -y && apt-get install -y \
software-properties-common \
apt-transport-https \
curl \
# Only needed to build indy-sdk
build-essential
# Copy files required for yarn install
COPY package.json package.json
COPY yarn.lock yarn.lock
COPY packages/rest/package.json packages/rest/package.json

# libindy
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CE7709D068DB5E88
RUN add-apt-repository "deb https://repo.sovrin.org/sdk/deb bionic stable"
# Install dependencies
RUN yarn install

# nodejs
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash
# The build stage installs all node_modules (also dev)
# and build the JS files to run the REST server
FROM all-dependencies as build

# yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
# Copy remaining files for rest package and build the JS files
COPY tsconfig.build.json tsconfig.build.json
COPY packages/rest packages/rest
WORKDIR /all-dependencies/packages/rest
RUN yarn build

# install depdencies
RUN apt-get update -y && apt-get install -y --allow-unauthenticated \
libindy \
nodejs
# The production-dependencies stage installs only the production node_modules
# It is based on the all-dependencies so it can use the yarn-cache and doesn't
# have to re-fetch all deps (as prod deps are a subset of all deps)
FROM all-dependencies as production-dependencies

# Install yarn seperately due to `no-install-recommends` to skip nodejs install
RUN apt-get install -y --no-install-recommends yarn
WORKDIR /production-dependencies

# Credo specifc setup
WORKDIR /www
COPY packages/rest/package.json package.json
COPY yarn.lock yarn.lock

COPY bin ./bin
COPY package.json package.json
RUN yarn install --production

COPY build ./build
FROM node:20 as final

WORKDIR /app

# Copy build files
COPY --from=build /all-dependencies/packages/rest/build build

# Copy dependencies
COPY --from=production-dependencies /production-dependencies/node_modules node_modules

# Copy source files
COPY packages/rest/bin bin
COPY packages/rest/package.json package.json

ENTRYPOINT [ "./bin/credo-rest.js", "start" ]
Loading
Loading