Skip to content

Commit

Permalink
chore: add dockerfile, update node version, use yarn instead of npm (#38
Browse files Browse the repository at this point in the history
)

* chore: use yarn instead of npm, minor vue update, major ts update, align @types/node to v16

* chore: add docker and compose support

* fix(ts): tackle build errors, no-check some files, assert some assignements

* fix: update gh action to use nvmrc and yarn

* feat(actions): gh action to push image to ghcr

* fix: yarn instead of npm to build in action
  • Loading branch information
akanoce authored Jan 4, 2024
1 parent 2d5db9f commit 9920629
Show file tree
Hide file tree
Showing 20 changed files with 8,276 additions and 25,173 deletions.
34 changes: 34 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/engine/reference/builder/#dockerignore-file

**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.next
**/.cache
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/build
**/dist
LICENSE
README.md
26 changes: 10 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,19 @@ jobs:
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v3

- uses: actions/setup-node@v2
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '10'
node-version-file: .nvmrc

- name: Cache Node.js modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
- name: Install Dependencies
run: npm ci

- name: Build Website
run: npm run build
- name: Install & Patch packages
run: yarn install

- name: Build app
run: yarn build

- name: Deploy Without CNAME
if: ${{ github.repository_owner != 'vechain' }}
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/push-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish image to GHCR

on:
workflow_call:
release:
types: [published]

jobs:
build:
env:
REGISTRY: ghcr.io
IMAGE_NAME: vechain/insight-app
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Download artifact explorer
uses: actions/download-artifact@v2
with:
name: insight-app
path: /tmp
- name: Load Docker images
run: |
docker load --input /tmp/insight-app.tar
docker image ls -a
- name: Tags images to publish
run: |
timestamp=`date +%s`
docker tag insight-app ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${timestamp}
docker tag insight-app ${{env.REGISTRY}}/${{env.IMAGE_NAME}}
docker tag insight-app ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{github.sha}}
- name: Publish images
run: |
docker push -a ${{env.REGISTRY}}/${{env.IMAGE_NAME}}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.20.0
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/engine/reference/builder/

ARG NODE_VERSION=16.20.0

################################################################################
# Use node image for base image for all stages.
FROM node:${NODE_VERSION}-alpine AS base

# Set working directory for all build stages.
WORKDIR /usr/src/app


################################################################################
# Create a stage for installing production dependecies.
FROM base AS deps

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.yarn to speed up subsequent builds.
# Leverage bind mounts to package.json and yarn.lock to avoid having to copy them
# into this layer.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=yarn.lock,target=yarn.lock \
--mount=type=cache,target=/root/.yarn \
yarn install --production --frozen-lockfile

################################################################################
# Create a stage for building the application.
FROM deps AS build

# Download additional development dependencies before building, as some projects require
# "devDependencies" to be installed to build. If you don't need this, remove this step.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=yarn.lock,target=yarn.lock \
--mount=type=cache,target=/root/.yarn \
yarn install --frozen-lockfile

# Copy the rest of the source files into the image.
COPY . .
# Run the build script.
RUN yarn run build

################################################################################
# Create a new stage to run the application with minimal runtime dependencies
# where the necessary files are copied from the build stage.
FROM nginx:stable-alpine AS final
COPY --from=build /usr/src/app/dist /usr/share/nginx/html
# COPY --from=build /usr/src/app/nginx.prod.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
50 changes: 50 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Docker compose reference guide at
# https://docs.docker.com/compose/compose-file/

# Here the instructions define your application as a service called "server".
# This service is built from the Dockerfile in the current directory.
# You can add other services your application may depend on here, such as a
# database or a cache. For examples, see the Awesome Compose repository:
# https://github.com/docker/awesome-compose
services:
server:
build:
context: .
environment:
NODE_ENV: production
ports:
- 8080:80
# The commented out section below is an example of how to define a PostgreSQL
# database that your application can use. `depends_on` tells Docker Compose to
# start the database before your application. The `db-data` volume persists the
# database data between container restarts. The `db-password` secret is used
# to set the database password. You must create `db/password.txt` and add
# a password of your choosing to it before running `docker-compose up`.
# depends_on:
# db:
# condition: service_healthy
# db:
# image: postgres
# restart: always
# user: postgres
# secrets:
# - db-password
# volumes:
# - db-data:/var/lib/postgresql/data
# environment:
# - POSTGRES_DB=example
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
# expose:
# - 5432
# healthcheck:
# test: [ "CMD", "pg_isready" ]
# interval: 10s
# timeout: 5s
# retries: 5
# volumes:
# db-data:
# secrets:
# db-password:
# file: db/password.txt

Loading

0 comments on commit 9920629

Please sign in to comment.