Skip to content

Commit

Permalink
push 0.0.16 to git
Browse files Browse the repository at this point in the history
  • Loading branch information
Raj Nandan Sharma authored and Raj Nandan Sharma committed Nov 12, 2024
1 parent 5abfafe commit c57f75d
Show file tree
Hide file tree
Showing 65 changed files with 7,160 additions and 907 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
NODE_ENV=production
PORT=3000
GH_TOKEN=your_github_token
API_TOKEN=your_api_token
API_IP=""
API_IP_REGEX=""
KENER_BASE_PATH=""
28 changes: 8 additions & 20 deletions .github/workflows/publishImage.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,57 @@
---
name: Publish Docker image to Dockerhub and GHCR

on:
push:
branches:
- 'main'
# add additional branches that should build to images here
# they will be tagged based on the branch name IE kener:test
#- 'test'
- main
- release-candidate/0.0.*
tags:
- '*.*.*'
# don't trigger if just updating docs
- "*.*.*"
paths-ignore:
- 'docs.md'
- 'README.md'

- docs.md
- README.md
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
# only run if we've specified image tag to push to
if: ${{ vars.DOCKERHUB_IMAGE_NAME != '' || vars.GHCR_IMAGE_NAME != '' }}
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
packages: write
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Log in to Docker Hub
if: ${{ github.event_name != 'pull_request' && vars.DOCKERHUB_IMAGE_NAME != '' }}
if: ${{ github.event_name != 'pull_request' && vars.DOCKERHUB_IMAGE_NAME != ''
}}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && vars.GHCR_IMAGE_NAME != '' }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: |
${{ vars.DOCKERHUB_IMAGE_NAME }}
${{ vars.GHCR_IMAGE_NAME }}
# generate Docker tags based on the following events/attributes
tags: |
type=raw,value=latest,enable=${{ endsWith(github.ref, 'main') }}
type=ref,event=branch,enable=${{ !endsWith(github.ref, 'main') }}
type=semver,pattern={{version}}
flavor: |
latest=false
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ nodemon.json
.okgit/
config/static/*
!config/static/.kener
db/*
!db/.kener
src/lib/server/data/*
!src/lib/server/data/.kener
src/lib/server/config/monitors.yaml
Expand Down
97 changes: 45 additions & 52 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,74 +1,67 @@
FROM lsiobase/alpine:3.18 as base
# Stage 1: Base image
FROM lsiobase/alpine:3.18 AS build

# Set timezone and user
ENV TZ=Etc/GMT
ENV PUID=911
ENV PGID=911

RUN \
echo "**** install build packages ****" && \
apk add --no-cache \
# Install Node.js and npm
RUN echo "**** install build packages ****" && \
apk add --no-cache \
nodejs \
npm && \
echo "**** cleanup ****" && \
rm -rf \
echo "**** cleanup ****" && \
rm -rf \
/root/.cache \
/tmp/*

# set OS timezone specified by docker ENV
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# Configure timezone
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone

ARG data_dir=/config
VOLUME $data_dir
ENV CONFIG_DIR=$data_dir

COPY docker/root/ /
# Set working directory
WORKDIR /app

# Dir ENVs need to be set before building or else build throws errors
ENV PUBLIC_KENER_FOLDER=/config/static \
MONITOR_YAML_PATH=/config/monitors.yaml \
SITE_YAML_PATH=/config/site.yaml

# build requires devDependencies which are not used by production deploy
# so build in a stage so we can copy results to clean "deploy" stage later
FROM base as build

WORKDIR /app
# Copy package files first for better caching
COPY package*.json ./

COPY --chown=abc:abc . /app
# Install dependencies
RUN npm install

# build requires PUBLIC_KENER_FOLDER dir exists so create temporarily
# -- it is non-existent in final stage to allow proper startup and chown'ing/example population
RUN mkdir -p "${CONFIG_DIR}"/static \
&& npm install \
&& chown -R root:root node_modules \
&& npm run kener:build
# Copy project files
COPY . .

FROM base as app
# Create database directory
RUN mkdir -p /app/database && \
chown -R $PUID:$PGID /app/database && \
chmod -R 755 /app/database

# copy package, required libs (npm,nodejs) results of build, prod entrypoint, and examples to be used to populate config dir
# to clean, new stage
COPY --chown=abc:abc package*.json ./
COPY --from=base /usr/local/bin /usr/local/bin
COPY --from=base /usr/local/lib /usr/local/lib
COPY --chown=abc:abc scripts /app/scripts
COPY --chown=abc:abc static /app/static
COPY --chown=abc:abc locales /app/locales
COPY --chown=abc:abc config /app/config
COPY --chown=abc:abc src/lib/helpers.js /app/src/lib/helpers.js
COPY --from=build --chown=abc:abc /app/build /app/build
COPY --from=build --chown=abc:abc /app/prod.js /app/prod.js
# Set production environment
ENV NODE_ENV=production \
PORT=3000 \
TZ=Etc/GMT \
PUID=911 \
PGID=911
# Copy database contents if they exist
# Declare volume for persistence
VOLUME /app/database


ENV NODE_ENV=production
# Build application
RUN node build.js && \
npm run build

# install prod depdendencies and clean cache
RUN npm install --omit=dev \
&& npm cache clean --force \
&& chown -R abc:abc node_modules
RUN npm install -g vite-node

ARG webPort=3000
ENV PORT=$webPort
# Use PORT env variable
EXPOSE $PORT

# leave entrypoint blank!
# uses LSIO s6-init entrypoint with scripts
# that populate CONFIG_DIR with static dir, monitor/site.yaml when dir is empty
# and chown's all files so they are owned by proper user based on PUID/GUID env
# Print PORT env variable
RUN echo "PORT: $PORT"

# Set startup command

CMD ["sh", "-c", "vite-node src/lib/server/startup.js & node main.js & wait"]
Loading

0 comments on commit c57f75d

Please sign in to comment.