Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Feature/docker image and deployment (#4)
Browse files Browse the repository at this point in the history
* Added dockerfile for simple image of Dashboard

---------

Co-authored-by: Kamil Stasiak <[email protected]>
  • Loading branch information
Crackhoff and kamil-stasiak authored Aug 17, 2023
1 parent af3d269 commit 870c26c
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
build
.dockerignore
Dockerfile
.gitignore
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"plugin:@typescript-eslint/recommended"
],
"rules": {
"eol-last": ["error", "always"],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error",
"@typescript-eslint/ban-ts-comment": "off",
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/dockerize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
name: Create and publish a Docker image

# Configures this workflow to run every time a change is pushed to the main with the tag of current version. Testing version
on:
push:
branches:
- main
tags:
- "v*.*.*"

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the GitHub Hub
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dist
dist-ssr
docs
*.local
.secrets
.env

# Editor directories and files
.vscode/*
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:19.5.0-alpine as builder

WORKDIR /app

COPY . ./

RUN npm ci

RUN npm run build

# Bundle static assets with nginx
FROM nginx:1.25-alpine as development
# Copy built assets from `builder` image
COPY --from=builder app/dist /usr/share/nginx/html
# Add your nginx.conf
COPY nginx.conf /nginx.conf
# Expose port
EXPOSE 3001
# Start nginx
CMD ["nginx", "-c", "/nginx.conf", "-g", "daemon off;"]
56 changes: 56 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Determine the number of worker processes automatically
worker_processes auto;

# Events module configuration
events {
# Maximum number of simultaneous connections that can be opened by a worker process
worker_connections 1024;
}

http{
# Enable high-performance file transfer
sendfile on;

# Route to log files. Log level is set to warn
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;

server {
listen 3001;
server_name ${DOMAIN}; #Your domain

# Turn on gzip compression.
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss image/svg+xml;


location / {
# Enable Gzip static file serving.
gzip_static on;
# Enable runtime decompression before sending downstream.
gunzip on;

# Root directory
root /usr/share/nginx/html/;
index index.html;

# MIME types and caching
include /etc/nginx/mime.types;
expires 30d;

# add_header Cache-Control "public, no-transform";

add_header X-Frame-Options "SAMEORIGIN" always; # defence agains Clickjacking attacks
add_header X-XSS-Protection "1; mode=block" always; # defence agains Cross-Site Scripting (XSS) attacks
add_header X-Content-Type-Options "nosniff" always; # defence agains MIME type sniffing attacks

try_files $uri $uri/ /index.html;

# Hide the Nginx version number in the HTTP headers
server_tokens off;
}
}
}

0 comments on commit 870c26c

Please sign in to comment.