From 0665e1274d7e6b27ba6838f2f250713c61f009e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Malak?= Date: Thu, 18 Nov 2021 16:30:04 +0100 Subject: [PATCH] Created one Dockerfile for all platforms. Updated README file --- Dockerfile | 20 +++++-- Dockerfile.arm => Dockerfile.dev | 16 ++++-- README.md | 89 +++++++++++++++++--------------- 3 files changed, 72 insertions(+), 53 deletions(-) rename Dockerfile.arm => Dockerfile.dev (71%) diff --git a/Dockerfile b/Dockerfile index 58838f2..789f408 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,12 @@ -FROM node:14-alpine +FROM node:14-alpine3.11 AS builder WORKDIR /app COPY package*.json ./ -RUN npm install - +RUN apk --no-cache --virtual build-dependencies add python make g++ \ + && npm install + COPY . . # Install client dependencies @@ -14,13 +15,22 @@ RUN mkdir -p ./public ./data \ && npm install \ && npm rebuild node-sass -# Build +# Build RUN npm run build \ && mv ./client/build/* ./public # Clean up src files RUN rm -rf src/ ./client \ - && npm prune --production + && npm prune --production \ + && apk del build-dependencies + +FROM node:14-alpine + +USER node + +WORKDIR /app + +COPY --from=builder /app /app EXPOSE 5000 diff --git a/Dockerfile.arm b/Dockerfile.dev similarity index 71% rename from Dockerfile.arm rename to Dockerfile.dev index 667887f..132c398 100644 --- a/Dockerfile.arm +++ b/Dockerfile.dev @@ -1,11 +1,10 @@ -FROM node:14-alpine +FROM node:14-alpine AS builder WORKDIR /app COPY package*.json ./ -RUN apk --no-cache --virtual build-dependencies add python make g++ \ - && npm install +RUN npm install COPY . . @@ -21,8 +20,15 @@ RUN npm run build \ # Clean up src files RUN rm -rf src/ ./client \ - && npm prune --production \ - && apk del build-dependencies + && npm prune --production + +FROM node:14-alpine + +USER node + +WORKDIR /app + +COPY --from=builder /app /app EXPOSE 5000 diff --git a/README.md b/README.md index ee2cc09..ed5ec8a 100644 --- a/README.md +++ b/README.md @@ -6,62 +6,35 @@ Snippet Box is a simple self-hosted app for organizing your code snippets. It allows you to easily create, edit, browse and manage your snippets in various languages. With built-in Markdown support, Snippet Box makes it very easy to add notes or simple documentation to your code. -## Technology - -- Backend - - Node.js - - Typescript - - Express.js - - Sequelize ORM + SQLite -- Frontend - - React - - TypeScript - - Bootstrap -- Deployment - - Docker - -## Development - -```sh -# clone repository -git clone https://github.com/pawelmalak/snippet-box -cd snippet-box - -# install dependencies (run only once) -npm run init - -# start backend and frontend development servers -npm run dev -``` - ## Installation ### With Docker #### Docker Hub -[Docker Hub image link](https://hub.docker.com/r/pawelmalak/snippet-box). -For arm platforms use `:arm` tag. - -#### Building image +[Docker Hub link](https://hub.docker.com/r/pawelmalak/snippet-box) ```sh -# Building image for Linux -docker build -t snippet-box . - -# Build image for ARM -docker buildx build \ - --platform linux/arm/v7,linux/arm64 \ - -f Dockerfile.arm \ - -t snippet-box:arm . +docker pull pawelmalak/snippet-box ``` #### Deployment ```sh -# run container -# for ARM use snippet-box:arm tag -docker run -p 5000:5000 -v /path/to/data:/app/data snippet-box +# Create container +docker run -p 5000:5000 -v /path/to/host/data:/app/data pawelmalak/snippet-box +``` + +#### Building image + +```sh +# Building single image +docker build -t snippet-box . + +# Building multiarch image +docker buildx build \ + --platform linux/arm/v7,linux/arm64,linux/amd64 \ + -t snippet-box . ``` #### Docker Compose @@ -83,6 +56,36 @@ services: Follow instructions from wiki - [Installation without Docker](https://github.com/pawelmalak/snippet-box/wiki/Installation-without-Docker) +## Development + +### Technology + +- Backend + - Node.js + - Typescript + - Express.js + - Sequelize ORM + SQLite +- Frontend + - React + - TypeScript + - Bootstrap +- Deployment + - Docker + +### Creating dev environment + +```sh +# clone repository +git clone https://github.com/pawelmalak/snippet-box +cd snippet-box + +# install dependencies (run only once) +npm run init + +# start backend and frontend development servers +npm run dev +``` + ## Functionality - Search