Skip to content

Commit

Permalink
feat: prepare docker (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Bodin authored Jul 8, 2021
1 parent cbc545d commit 21b5d02
Show file tree
Hide file tree
Showing 8 changed files with 2,614 additions and 69 deletions.
41 changes: 40 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ version: 2.1
orbs:
node: circleci/node@4.5.1

aliases:
# Forward the current folder when using workflows
- &persist_work_dir
root: .
paths:
- .

- &attach_work_dir
at: ~/repo

jobs:
# Step build
build:
docker:
- image: cimg/node:14.16.1
Expand All @@ -12,9 +23,10 @@ jobs:

steps:
- checkout
- persist_to_workspace: *persist_work_dir

- node/install-packages:
pkg-manager: yarn
pkg-manager: yarn

- run:
name: Lint
Expand All @@ -28,10 +40,37 @@ jobs:
name: Test
command: yarn test

- persist_to_workspace: *persist_work_dir
- store_test_results:
path: junit/

# Step release
release:
docker:
- image: cimg/node:14.16.1
working_directory: ~/repo
steps:
- attach_workspace: *attach_work_dir
- run:
name: Release
command: yarn semantic-release
- run:
name: Docker Build
command: yarn docker:build
- run:
name: Docker publish
command: |
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
yarn docker:release
workflows:
suite:
jobs:
- build

- release:
requires:
- build
filters:
branches:
only: master
59 changes: 59 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Dependencies
**/node_modules

# Useless and heavy folders
**/dist
coverage/
junit/

# Logs
**/*.log
**/.env*

# Other useless files in the image
cypress/
.git/
.github/
.githooks/
.circleci/
.husky/
.nodemon.json
.editorconfig
.gitattributes
.coveralls.yml
.prettierignore
.prettierrc.js
.eslintrc.js
.nvmrc
.npmrc
.eslintignore
.eslinrcjs
.tern-project
cypress.json
cloudbuild.yaml
docker-compose.yml
MAINTAINERS.md
README.md
CHANGELOG.md
CONTRIBUTING.md
**/*.test.ts
**/*.test.tsx
**/*.test.js
**/*.stories.tsx
**/*.spec.ts
**/*.spec.js
**/*.perf.ts
package-lock.json
renovate.json
**/jest*
**/.DS_Store
.vscode
**/.storybook/
**/__fixtures__/
**/__snapshots__/
**/__mocks__/
**/__mock__/
**/__tests__/
**/tsconfig.tsbuildinfo
Procfile
release.config.js
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# ---- Base ----
FROM node:14.16.1-alpine AS base

ENV NODE_ENV production

# Setup the app WORKDIR
WORKDIR /app

# Copy and install dependencies separately from the app's code
# To leverage Docker's cache when no dependency has change
COPY package.json yarn.lock ./

# Install dev dependencies
RUN true \
# && yarn set version berry \
&& yarn install --production=false

# This step will invalidates cache
COPY . /app
RUN ls -lah /app

# Builds the code and reinstall node_modules in prod mode
RUN true \
&& yarn build \
&& yarn install --production=true \
&& rm -rf src/ \
&& rm -rf .yarn/

# ---- Final ----
# Resulting new, minimal image
# This image must have the minimum amount of layers
FROM node:14.16.1-alpine as final

# Do not use root to run the app
USER node

WORKDIR /app

COPY --from=base --chown=node:node /app /app

EXPOSE 8000

CMD [ "npm", "start" ]
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
"build:hot": "tsc -w --preserveWatchOutput",
"build": "tsc -b",
"clean": "rm -rf dist/",
"dev": "",
"dev": "node -r dotenv/config --async-stack-traces --max-old-space-size=920 dist/index.js",
"doctoc": "doctoc --notitle --maxlevel 3 README.md",
"lint": "eslint --ext=jsx,ts,tsx,js .",
"prepare": "husky install",
"start": "UV_THREADPOOL_SIZE=64 node -r dotenv/config --async-stack-traces --max-old-space-size=920 dist/index.js",
"start": "UV_THREADPOOL_SIZE=64 node --async-stack-traces --max-old-space-size=920 dist/index.js",
"start_new": "indexName=npm-search-new bootstrapIndexName=npm-search-new.tmp UV_THREADPOOL_SIZE=64 node --async-stack-traces --max-old-space-size=920 dist/index.js",
"test:watch": "jest --watchAll --no-watchman",
"test": "jest --forceExit"
"test": "jest --forceExit",
"docker:build": "./scripts/build.sh",
"docker:release": "VERSION=$(node -e \"console.log(require('./package.json').version)\") && echo \"Releasing $VERSION\" && docker push algolia/npm-search && docker push algolia/npm-search:$VERSION"
},
"renovate": {
"extends": [
Expand All @@ -33,7 +35,6 @@
"async": "3.2.0",
"bunyan": "1.8.15",
"bunyan-debug-stream": "2.0.0",
"dotenv": "10.0.0",
"dtrace-provider": "0.8.8",
"escape-html": "1.0.3",
"got": "11.8.2",
Expand All @@ -51,6 +52,9 @@
"truncate-utf8-bytes": "1.0.2"
},
"devDependencies": {
"@semantic-release/changelog": "5.0.1",
"@semantic-release/git": "9.0.0",
"@semantic-release/npm": "7.1.3",
"@types/async": "3.2.6",
"@types/escape-html": "1.0.1",
"@types/hosted-git-info": "3.0.1",
Expand All @@ -63,6 +67,7 @@
"@typescript-eslint/eslint-plugin": "4.26.0",
"@typescript-eslint/parser": "4.26.0",
"doctoc": "2.0.1",
"dotenv": "10.0.0",
"eslint": "7.30.0",
"eslint-config-algolia": "18.0.0",
"eslint-config-prettier": "8.3.0",
Expand All @@ -80,6 +85,7 @@
"pre-commit": "1.2.2",
"prettier": "2.3.2",
"renovate-config-algolia": "2.1.3",
"semantic-release": "17.4.4",
"ts-jest": "27.0.3",
"typescript": "4.3.2",
"validator": "13.6.0"
Expand Down
23 changes: 23 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable import/no-commonjs */
/* eslint-disable no-template-curly-in-string */
module.exports = {
branches: 'master',
verifyConditions: ['@semantic-release/github'],
prepare: [
{
path: '@semantic-release/changelog',
changelogFile: 'CHANGELOG.md',
},
'@semantic-release/npm',
{
path: '@semantic-release/git',
assets: ['package.json', 'CHANGELOG.md'],
message:
'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
},
],
publish: ['@semantic-release/github'],
success: [],
fail: [],
npmPublish: false,
};
12 changes: 12 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/sh

set -e

current=$(node -e "console.log(require('./package.json').version)")
echo "Releasing: $current"
echo ""

docker build \
-t algolia/npm-search \
-t "algolia/npm-search:${current}" \
.
Loading

0 comments on commit 21b5d02

Please sign in to comment.