Skip to content

Commit

Permalink
Updates to Workflow, Dockerfile, s6-Overlay, and Configuration Files (#…
Browse files Browse the repository at this point in the history
…18)

* Update Dockerfile

Signed-off-by: HUSSAIN GANDHI <69318875+HussainTechSavvy@users.noreply.github.com>

* Update build.yaml

Signed-off-by: HUSSAIN GANDHI <69318875+HussainTechSavvy@users.noreply.github.com>

* Update build.yaml

Signed-off-by: HUSSAIN GANDHI <69318875+HussainTechSavvy@users.noreply.github.com>

* Create .dockerignore

Signed-off-by: HUSSAIN GANDHI <69318875+HussainTechSavvy@users.noreply.github.com>

* Update Dockerfile

Signed-off-by: HUSSAIN GANDHI <69318875+HussainTechSavvy@users.noreply.github.com>

* Update Dockerfile

Signed-off-by: HUSSAIN GANDHI <69318875+HussainTechSavvy@users.noreply.github.com>

* Added editorconfig

* Optimized the s6-overlay scripts

* fix: Changed the CI trriger conditions

* feat: upgraded alpine version 3.20

---------

Signed-off-by: HUSSAIN GANDHI <69318875+HussainTechSavvy@users.noreply.github.com>
  • Loading branch information
HussainTechSavvy authored Nov 21, 2024
1 parent a7fb681 commit 358ce0b
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 68 deletions.
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Git
.git
.gitignore

# Docker
.dockerignore
Dockerfile

# GitHub files
.github/

# Documentation and License
*.md
LICENSE
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yaml]
indent_size = 2

[*.yml]
indent_size = 2
55 changes: 39 additions & 16 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,52 +1,75 @@
name: Build and Push
on:
push:
branches:
- "main"
paths-ignore:
- ".editorconfig"
- ".gitignore"
- "**.md"
pull_request:
branches:
- "main"

env:
ALPINE_VERSION: "3.18"
ALPINE_VERSION: "3.20"

jobs:
build:
name: Build and Push Image
docker-build:
name: Docker Build
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [ 14.19.1,18, 19, 20,20.13.1,20.17.0,22.11.0] # List of Node.js versions to test
node-version: [14.19.1, 18, 19, 20, 20.13.1, 20.17.0, 22.11.0] # Node.js versions

steps:
- name: Checkout code
- name: Checkout Code
uses: actions/checkout@v4
timeout-minutes: 5
with:
fetch-depth: 1
timeout-minutes: 3

- name: Docker meta
- name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: improwised/docker-nodejs-base
tags: |
type=raw,value=${{ matrix.node-version }}-{{sha}}-{{date 'X'}}
type=raw,value=${{ matrix.node-version }}-latest
type=raw,value=${{ matrix.node-version }}-{{sha}}-{{date 'X'}}
timeout-minutes: 2

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

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

- name: PR Tags
id: fallback-tags
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "tags=test-${{ matrix.node-version }}-${{ github.sha }}" >> $GITHUB_ENV
timeout-minutes: 1

- name: Build and Push Docker Image
- name: Build & Push
uses: docker/build-push-action@v6
with:
context: .
build-args: |
NODE_VERSION=${{ matrix.node-version }}
ALPINE_VERSION=${{ env.ALPINE_VERSION }}
context: .
push: ${{ github.ref_name == 'main' }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
push: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
tags: ${{ github.event_name == 'pull_request' && env.tags || steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
timeout-minutes: 10
87 changes: 40 additions & 47 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,62 +1,55 @@
# Default version for NodeJS and Alpine Linux
ARG NODE_VERSION
ARG ALPINE_VERSION
# Use default versions for Node.js and Alpine Linux
ARG NODE_VERSION=current
ARG ALPINE_VERSION=latest

# Base images
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.2.0.0"
# Set version variables
ARG DOCKERIZE_VERSION="v0.8.0"
ARG S6_OVERLAY_VERSION="3.2.0.2"
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 dependencies and tools
RUN apk add --no-cache \
bash \
curl \
make \
gcc \
g++ \
nginx \
ca-certificates \
coreutils \
tzdata \
shadow && \
apk add --no-cache --virtual=build-dependencies tar && \
# Add Dockerize
wget -q 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 && \
# Create necessary directories for Nginx
mkdir -p /etc/nginx && \
touch /var/log/nginx/error.log && \
rm -Rf /etc/nginx/nginx.conf && \
# Cleanup
apk del --purge build-dependencies && \
rm -rf /tmp/*

# 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/*
# Add Node.js libraries from the Node image
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 Overlay
RUN wget -qO- https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz | tar -C / -Jx && \
wget -qO- https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_OVERLAY_ARCH}.tar.xz | tar -C / -Jx && \
wget -qO- https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz | tar -C / -Jx && \
wget -qO- https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz | tar -C / -Jx

# 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
# Set working directory
WORKDIR /app

# Copy s6-overlay files
ADD rootfs /
6 changes: 3 additions & 3 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-nginx/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/with-contenv sh

set -ex
cat /etc/nginx/nginx.conf
exec nginx;
set -e

exec nginx
6 changes: 4 additions & 2 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-node-app/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/with-contenv bash

cd /app
set -e

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

set -e

dockerize -stdout /var/log/nginx/error.log -poll

0 comments on commit 358ce0b

Please sign in to comment.