Skip to content

Commit

Permalink
Nodejs dockerfile (#3)
Browse files Browse the repository at this point in the history
* feat: Add Dockerfile with S6-Overlay, Dockerize and nginx #1
  • Loading branch information
Luv7804 authored Jan 19, 2024
1 parent b950a40 commit f47ddfc
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 1 deletion.
44 changes: 44 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build and Push
on:
push:

env:
NODE_VERSION: "20.10.0"
ALPINE_VERSION: "3.18"

jobs:
build:
name: Build and Push Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
timeout-minutes: 5

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
timeout-minutes: 5

- name: Create Tag
id: tag
run: echo "tag=${{ env.NODE_VERSION }}-$(git rev-parse --short HEAD)-$(date +%s)" >> $GITHUB_OUTPUT
timeout-minutes: 5

- name: Login to Docker Hub
if: ${{ github.ref_name == 'main' }}
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
timeout-minutes: 5

- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
build-args: |
NODE_VERSION=${{ env.NODE_VERSION }}
ALPINE_VERSION=${{ env.ALPINE_VERSION }}
context: .
push: ${{ github.ref_name == 'main' }}
tags: "improwised/docker-nodejs-base:${{ steps.tag.outputs.tag }}"
timeout-minutes: 10
62 changes: 62 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Default version for NodeJS and Alpine Linux
ARG NODE_VERSION
ARG ALPINE_VERSION

FROM node:${NODE_VERSION}-alpine AS node
FROM alpine:${ALPINE_VERSION}

# set version for Dockerrize
ENV DOCKERIZE_VERSION v0.6.1

# set version for s6 overlay
ARG S6_OVERLAY_VERSION="3.1.5.0"
ARG S6_OVERLAY_ARCH="x86_64"

# add Dockerize
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz

# Install OS Dependencies
RUN \
apk add --no-cache --virtual=build-dependencies \
tar && \
apk add --no-cache \
bash \
curl \
make \
gcc \
g++ \
nginx \
&& mkdir -p /etc/nginx \
&& touch /var/log/nginx/error.log \
&& rm -Rf /etc/nginx/nginx.conf \
ca-certificates \
coreutils \
tzdata && \
apk add --no-cache \
--repository http://nl.alpinelinux.org/alpine/edge/community \
shadow && \
# clean up
apk del --purge \
build-dependencies && \
rm -rf \
/tmp/*
COPY --from=node /usr/lib /usr/lib
COPY --from=node /usr/local/lib /usr/local/lib
COPY --from=node /usr/local/include /usr/local/include
COPY --from=node /usr/local/bin /usr/local/bin

# add s6 overlay
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_OVERLAY_ARCH}.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-${S6_OVERLAY_ARCH}.tar.xz

# add s6 optional symlinks
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-symlinks-noarch.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-symlinks-arch.tar.xz
WORKDIR /app
ADD rootfs /
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# docker-nodejs-base
Base image for Node.js based applications
Base container image for modern NodeJS applications built on top of Alpine Linux.
5 changes: 5 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-nginx/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/with-contenv sh

set -ex
cat /etc/nginx/nginx.conf
exec nginx;
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-nginx/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
5 changes: 5 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-node-app/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/with-contenv bash

cd /app
# start our node.js application
npm start;
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-node-app/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-stdout/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash

dockerize -stdout /var/log/nginx/error.log -poll
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-stdout/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Empty file.

0 comments on commit f47ddfc

Please sign in to comment.