mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
Feat/docker container on main builds (#1762)
* feat: build docker containers when pushing to main The intent here is to publish a docker container for every build of main. This will make it easier to run the tip of main.
This commit is contained in:
parent
48747d70a6
commit
5d5fc37dfd
7
.dockerignore
Normal file
7
.dockerignore
Normal file
@ -0,0 +1,7 @@
|
||||
*
|
||||
!src
|
||||
!package.json
|
||||
!docker
|
||||
!yarn.lock
|
||||
!scripts
|
||||
!tsconfig.json
|
41
.github/workflows/docker_publish_main.yaml
vendored
Normal file
41
.github/workflows/docker_publish_main.yaml
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
name: Publish main branch to dockerhub
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
version: [14-alpine, 16-alpine]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup QEmu so we can build multiplatform
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Setup Docker buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Docker meta configuration
|
||||
uses: docker/metadata-action@v3
|
||||
id: meta
|
||||
with:
|
||||
images: |
|
||||
unleashorg/unleash-server
|
||||
tags: |
|
||||
type=edge,prefix=main-,suffix=-${{ matrix.version }}
|
||||
- name: Login to docker hub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build tag and push image to Docker hub
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
build-args: NODE_VERSION=${{ matrix.version }}
|
@ -52,7 +52,6 @@ Congratulations! The whole Unleash community thanks you. :sparkles:
|
||||
|
||||
Once your PR is merged, you will be proudly listed as a contributor in the [contributor chart](https://github.com/unleash/Unleash/graphs/contributors).
|
||||
|
||||
|
||||
## How to run the project
|
||||
|
||||
Install the required prerequisites and then follow the steps below.
|
||||
@ -60,22 +59,23 @@ Install the required prerequisites and then follow the steps below.
|
||||
### Prerequisites
|
||||
|
||||
You'll need:
|
||||
- [Docker](https://www.docker.com/) to run the database
|
||||
- [Node.js](https://nodejs.org/en/) to run the project. You can install it directly, or use `nvm` (see the next point) to manage it for you.
|
||||
- [nvm](https://github.com/nvm-sh/nvm) (optional) to manage your Node.js installation.
|
||||
- [Yarn](https://yarnpkg.com/) (optional but recommended; the steps below assume that you have it installed) to install packages and run the project.
|
||||
|
||||
### Steps
|
||||
- [Docker](https://www.docker.com/) to run the database
|
||||
- [Node.js](https://nodejs.org/en/) to run the project. You can install it directly, or use `nvm` (see the next point) to manage it for you.
|
||||
- [nvm](https://github.com/nvm-sh/nvm) (optional) to manage your Node.js installation.
|
||||
- [Yarn](https://yarnpkg.com/) (optional but recommended; the steps below assume that you have it installed) to install packages and run the project.
|
||||
|
||||
### How to run Unleash with Node.js
|
||||
|
||||
1. Use `nvm` to **install the correct version of Node.js**. From anywhere in the repo, run the below command. Skip this step if you're managing your Node.js installations yourself.
|
||||
|
||||
``` bash
|
||||
```bash
|
||||
nvm use
|
||||
```
|
||||
|
||||
2. **Install packages**:
|
||||
|
||||
``` bash
|
||||
```bash
|
||||
yarn
|
||||
```
|
||||
|
||||
@ -94,7 +94,7 @@ You'll need:
|
||||
postgres
|
||||
```
|
||||
|
||||
The **connection details** that Unleash will try to use are found in **`src/server-dev.ts`**. The above command works with the current defaults (at the time of writing).
|
||||
The **connection details** that Unleash will try to use are found in **`src/server-dev.ts`**. The above command works with the current defaults (at the time of writing).
|
||||
|
||||
- If you've set up the database previously, you can restart the container by running this (assuming `postgres` is the name you gave the container):
|
||||
|
||||
@ -103,10 +103,37 @@ You'll need:
|
||||
```
|
||||
|
||||
4. **Start the server.** Run the below command and the server will start up and try to connect to the database. On a successful connection it will also configure the database for Unleash.
|
||||
``` bash
|
||||
|
||||
```bash
|
||||
yarn start:dev
|
||||
```
|
||||
|
||||
5. **Log into the admin UI**. Use a browser and navigate to `localhost:4242`. Log in using:
|
||||
- username: `admin`
|
||||
- password: `unleash4all`
|
||||
|
||||
### How to run Unleash with Docker
|
||||
|
||||
1. Build a local docker image by running `docker build . -t unleash:local`
|
||||
2. Create a network by running `docker network create unleash`
|
||||
3. Start a Postgres database. Make sure to use the network you created in step 2.
|
||||
|
||||
```sh
|
||||
docker run -e POSTGRES_PASSWORD=passord \
|
||||
-e POSTGRES_USER=unleash_user -e POSTGRES_DB=unleash \
|
||||
--network unleash --name postgres postgres
|
||||
```
|
||||
|
||||
4. Start Unleash. As with the database, use the network you created in step 2.
|
||||
|
||||
```sh
|
||||
docker run -p 4242:4242 \
|
||||
-e DATABASE_HOST=postgres -e DATABASE_NAME=unleash \
|
||||
-e DATABASE_USERNAME=unleash_user -e DATABASE_PASSWORD=passord \
|
||||
-e DATABASE_SSL=false \
|
||||
--network unleash unleash:local
|
||||
```
|
||||
|
||||
5. **Log into the admin UI**. Use a browser and navigate to `localhost:4242`. Log in using:
|
||||
- username: `admin`
|
||||
- password: `unleash4all`
|
||||
@ -117,12 +144,7 @@ Have any issues when getting set up?
|
||||
|
||||
#### Can't connect to the database
|
||||
|
||||
If you can't connect to the docker container, check its status by running `docker ps`.
|
||||
This command lists the currently running containers.
|
||||
Find the name of the container that you set up.
|
||||
If it's there, make sure that its port is mapped to your local machine:
|
||||
It should look this: `0.0.0.0:5432->5432/tcp` with the arrow (`->`) connector.
|
||||
If it just says `5432/tcp`, it is _not_ exposed to your local network.
|
||||
If you can't connect to the docker container, check its status by running `docker ps`. This command lists the currently running containers. Find the name of the container that you set up. If it's there, make sure that its port is mapped to your local machine: It should look like this: `0.0.0.0:5432->5432/tcp` with the arrow (`->`) connector. If it just says `5432/tcp`, it is _not_ exposed to your local network.
|
||||
|
||||
To fix this, start a new container and make sure you give it the `-p 5432:5432` option.
|
||||
|
||||
@ -133,12 +155,14 @@ To fix this, start a new container and make sure you give it the `-p 5432:5432`
|
||||
In order to handle HTTP requests we have an abstraction called [Controller](https://github.com/Unleash/unleash/blob/master/src/lib/routes/controller.ts). If you want to introduce a new route handler for a specific path (and sub pats) you should implement a controller class which extends the base Controller. An example to follow is the [routes/admin-api/feature.ts](https://github.com/Unleash/unleash/blob/master/src/lib/routes/admin-api/feature.ts) implementation.
|
||||
|
||||
The controller takes care of the following:
|
||||
|
||||
- try/catch RequestHandler method
|
||||
- error handling with proper response code if they fail
|
||||
- `await` the RequestHandler method if it returns a promise (so you don't have to)
|
||||
- access control so that you can just list the required permission for a RequestHandler and the base Controller will make sure the user have these permissions.
|
||||
|
||||
## Creating a release
|
||||
|
||||
In order to produce a release you will need to be a Unleash core team member and have the Unleash admin role assigned on the Unleash organization on GitHub.
|
||||
|
||||
### Step 1: create a new version tag
|
||||
@ -151,10 +175,10 @@ npm version 3.10.0
|
||||
|
||||
This command will trigger an internal verification step where we will perform the following steps:
|
||||
|
||||
- *STEP 1. Check unleash-frontend version* - Validate that a latest release of unleash-server does not depend on a pre-release of unleash-frontend (beta, alpha, etc)
|
||||
- *STEP 2. Lint* - Run lint checks on the code.
|
||||
- *STEP 3. Build* - Validate that we are able to build the project
|
||||
- *STEP 4. Test* - Validate that all test runs green.
|
||||
- _STEP 1. Check unleash-frontend version_ - Validate that a latest release of unleash-server does not depend on a pre-release of unleash-frontend (beta, alpha, etc)
|
||||
- _STEP 2. Lint_ - Run lint checks on the code.
|
||||
- _STEP 3. Build_ - Validate that we are able to build the project
|
||||
- _STEP 4. Test_ - Validate that all test runs green.
|
||||
|
||||
If all steps completes a single commit is produced on the main branch where the `version` property in package.json is updated, and a git tag is created to point to that tag specifically.
|
||||
|
||||
|
30
Dockerfile
Normal file
30
Dockerfile
Normal file
@ -0,0 +1,30 @@
|
||||
ARG NODE_VERSION=16-alpine
|
||||
FROM node:$NODE_VERSION as builder
|
||||
|
||||
RUN echo "Debug - node version: $NODE_VERSION "
|
||||
|
||||
WORKDIR /unleash
|
||||
|
||||
COPY . /unleash
|
||||
|
||||
RUN yarn install --frozen-lockfile --ignore-scripts && yarn run build
|
||||
|
||||
WORKDIR /unleash/docker
|
||||
|
||||
RUN yarn install --frozen-lockfile --production=true
|
||||
|
||||
FROM node:$NODE_VERSION
|
||||
|
||||
ENV NODE_ENV production
|
||||
|
||||
WORKDIR /unleash
|
||||
|
||||
COPY --from=builder /unleash/docker /unleash
|
||||
|
||||
RUN rm -rf /usr/local/lib/node_modules/npm/
|
||||
|
||||
EXPOSE 4242
|
||||
|
||||
USER node
|
||||
|
||||
CMD ["node", "index.js"]
|
7
docker/index.js
Normal file
7
docker/index.js
Normal file
@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const unleash = require('unleash-server');
|
||||
|
||||
let options = {};
|
||||
|
||||
unleash.start(options);
|
41
docker/package.json
Normal file
41
docker/package.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "unleash-docker",
|
||||
"description": "Docker images for unleash.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "NODE_ENV=production node index.js",
|
||||
"test:ci": "echo 'no tests for unleash-docker'"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@exlinc/keycloak-passport": "^1.0.2",
|
||||
"@passport-next/passport": "^3.1.0",
|
||||
"@passport-next/passport-google-oauth2": "^1.0.0",
|
||||
"basic-auth": "^2.0.1",
|
||||
"passport": "^0.5.2",
|
||||
"unleash-server": "file:./../"
|
||||
},
|
||||
"resolutions": {
|
||||
"async": "^3.2.3",
|
||||
"db-migrate/rc/minimist": "^1.2.5",
|
||||
"knex/liftoff/object.map/**/kind-of": "^6.0.3",
|
||||
"knex/liftoff/findup-sync/micromatc/kind-of": "^6.0.3",
|
||||
"knex/liftoff/findup-sync/micromatc/nanomatch/kind-of": "^6.0.3",
|
||||
"knex/liftoff/findup-sync/micromatch/define-property/**/kind-of": "^6.0.3",
|
||||
"set-value": "^4.0.1",
|
||||
"ansi-regex": "^5.0.1",
|
||||
"ssh2": "^1.4.0",
|
||||
"json-schema": "^0.4.0"
|
||||
},
|
||||
"overrides": {
|
||||
"set-value": "^4.0.1",
|
||||
"ansi-regex": "^5.0.1",
|
||||
"ssh2": "^1.4.0",
|
||||
"json-schema": "^0.4.0"
|
||||
},
|
||||
"version": "4.12.6"
|
||||
}
|
2641
docker/yarn.lock
Normal file
2641
docker/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@ -63,12 +63,11 @@
|
||||
"skipLibCheck": true /* Skip type checking of declaration files. */,
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
},
|
||||
"types": [
|
||||
"src/types/openapi.d.ts"
|
||||
],
|
||||
"types": ["src/types/openapi.d.ts"],
|
||||
"exclude": [
|
||||
"bin",
|
||||
"docs",
|
||||
"docker",
|
||||
"examples",
|
||||
"migrations",
|
||||
"node_modules",
|
||||
|
Loading…
Reference in New Issue
Block a user