Skip to content

Commit

Permalink
Merge pull request #66 from CodeForPhilly/develop
Browse files Browse the repository at this point in the history
Release: v0.1.1
  • Loading branch information
themightychris authored Dec 13, 2023
2 parents aef6135 + c657730 commit 140bc92
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 29 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/containers-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: 'Containers: Publish'

on:
push:
tags: [ 'v*' ]


jobs:
release-containers:
name: Build and Push
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3

- name: Login to ghcr.io Docker registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Compute Docker container image addresses
run: |
DOCKER_REPOSITORY="ghcr.io/${GITHUB_REPOSITORY,,}"
DOCKER_TAG="${GITHUB_REF:11}"
echo "DOCKER_REPOSITORY=${DOCKER_REPOSITORY}" >> $GITHUB_ENV
echo "DOCKER_TAG=${DOCKER_TAG}" >> $GITHUB_ENV
echo "Using: ${DOCKER_REPOSITORY}/*:${DOCKER_TAG}"
# - name: 'Pull previous Docker container image: :latest'
# run: docker pull "${DOCKER_REPOSITORY}:latest" || true

- name: 'Pull previous Docker container image: frontend-static:latest'
run: docker pull "${DOCKER_REPOSITORY}/frontend-static:latest" || true

- name: 'Build Docker container image: frontend-static:latest'
run: |
docker build \
--cache-from "${DOCKER_REPOSITORY}/frontend-static:latest" \
--file frontend/Dockerfile.demo \
--build-arg SERVER_NAME=localhost \
--tag "${DOCKER_REPOSITORY}/frontend-static:latest" \
--tag "${DOCKER_REPOSITORY}/frontend-static:${DOCKER_TAG}" \
frontend
- name: 'Push Docker container image frontend-static:latest'
run: docker push "${DOCKER_REPOSITORY}/frontend-static:latest"

- name: 'Push Docker container image frontend-static:v*'
run: docker push "${DOCKER_REPOSITORY}/frontend-static:${DOCKER_TAG}"
#
#
# - name: 'Build Docker container image: backend:latest'
# run: |
# cd backend && \
# make && \
# docker image tag "${DOCKER_REPOSITORY}/backend/local:latest" "${DOCKER_REPOSITORY}/backend:latest"
#
# - name: Push Docker container image backend:latest
# run: docker push "${DOCKER_REPOSITORY}/backend:latest"
#
# - name: Push Docker container image backend:v*
# run: docker push "${DOCKER_REPOSITORY}/backend:${DOCKER_TAG}"

# - name: Push Docker container image :v*"
# run: docker push "${DOCKER_REPOSITORY}:${DOCKER_TAG}"
10 changes: 7 additions & 3 deletions server/Dockerfile.prod → Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# This image runs the production server, with nginx
###########
# BUILDER #
###########

# pull official base image
FROM python:3.11.4-slim-buster as builder
FROM python:3.11.4-slim-buster as python_builder

# set work directory
WORKDIR /usr/src/app
Expand Down Expand Up @@ -48,8 +49,8 @@ WORKDIR $APP_HOME

# install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends netcat
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
COPY --from=python_builder /usr/src/app/wheels /wheels
COPY --from=python_builder /usr/src/app/requirements.txt .
RUN pip install --upgrade pip
RUN pip install --no-cache /wheels/*

Expand All @@ -69,3 +70,6 @@ USER app

# run entrypoint.prod.sh
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]


# TODO: gunicorn stuff
5 changes: 3 additions & 2 deletions docker-compose.yml → docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
build: ./server
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./server:/usr/src/server
- ./server:/usr/src/app
ports:
- "8000:8000"
env_file:
Expand All @@ -23,9 +23,10 @@ services:
image: balancer-frontend
build:
context: frontend
dockerfile: Dockerfile
dockerfile: Dockerfile.dev
args:
- IMAGE_NAME=balancer-frontend
- FRONTEND_VERSION=0.0.1
ports:
- "3000:3000"
environment:
Expand Down
17 changes: 2 additions & 15 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.env.prod.db
- ./config/env/env.prod.db
backend:
build:
context: ./server
Expand All @@ -14,22 +14,9 @@ services:
ports:
- 8000:8000
env_file:
- ./config/env/.env.prod
- ./config/env/env.prod
depends_on:
- db
frontend:
image: balancer-frontend
build:
context: frontend
dockerfile: Dockerfile
args:
- IMAGE_NAME=balancer-frontend
ports:
- "3000:3000"
environment:
- CHOKIDAR_USEPOLLING=true
depends_on:
- backend

volumes:
postgres_data:
2 changes: 0 additions & 2 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ dist-ssr
*.njsproj
*.sln
*.sw?

.DS_Store
38 changes: 38 additions & 0 deletions frontend/Dockerfile.demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This dockerfile builds an image for a static frontend only server suitable for online hosting.
# Use the official Node.js image as the base image
FROM node:18 as builder

# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy package.json and package-lock.json
COPY package*.json ./

# Set version number
ARG FRONTEND_VERSION
RUN npm version $FRONTEND_VERSION

# Install dependencies
RUN npm ci --legacy-peer-deps

# Copy project files
COPY . .

RUN npm run build

FROM alpine:latest as nginx-config
RUN apk --no-cache add gettext
WORKDIR /app
COPY nginx.conf.demo ./nginx.conf.demo
# This will get overwritten by helm chart

ARG SERVER_NAME
ENV SERVER_NAME $SERVER_NAME
RUN cat nginx.conf.demo | envsubst > nginx.conf

FROM nginx:alpine

COPY --from=nginx-config /app/nginx.conf /etc/nginx/nginx.conf
COPY --from=Builder /usr/src/app/dist /usr/share/nginx/html

# The default entrypoint works for us.
9 changes: 5 additions & 4 deletions frontend/Dockerfile → frontend/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Use the official Node.js 14 image as the base image
# This dockerfile builds an image for a Vite development server
# Use the official Node.js image as the base image
FROM node:18

# Set the working directory inside the container
Expand All @@ -14,12 +15,12 @@ RUN npm ci --legacy-peer-deps
COPY . .

# Build the project
RUN npm run build
# RUN npm run build

# Expose a port if required
EXPOSE 3000
# EXPOSE 3000

# Start the application
# Start the dev server
CMD [ "npm", "run", "dev" ]

# Set the image name
Expand Down
16 changes: 16 additions & 0 deletions frontend/docker-compose.demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.8"
services:
frontend-static:
build:
context: .
dockerfile: Dockerfile.demo
args:
- IMAGE_NAME=frontend-static
- FRONTEND_VERSION=0.0.2
- SERVER_NAME=localhost
image: ghcr.io/codeforphilly/balancer-main/frontend-static:0.0.2
ports:
- "80:80"
environment:
- CHOKIDAR_USEPOLLING=true
- VITE_API_BASE_URL=https://devnull-as-a-service.com/dev/null
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ services:
react-app:
build:
context: .
dockerfile: Dockerfile
dockerfile: Dockerfile.dev
args:
- IMAGE_NAME=balancer-frontend
- IMAGE_NAME=balancer-frontend-dev
ports:
- "3000:3000"
# The port number is hard-coded, located in ./vite.config.ts
environment:
- CHOKIDAR_USEPOLLING=true
volumes:
- "./:/usr/src/app:delegated"
- "/usr/src/app/node_modules/"
- "./node_modules:/usr/src/app/node_modules/"
29 changes: 29 additions & 0 deletions frontend/nginx.conf.demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# nginx config file for static frontend demo site.
# This will be the nginx.conf in the docker image before it gets overwritten by kubernetes helm chart.
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
server {
listen 80;
listen [::]:80;
server_name $SERVER_NAME;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
9 changes: 9 additions & 0 deletions helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: nginx-helm-chart
description: A generated Helm Chart for nginx-helm-chart from Skippbox Kompose
version: 0.0.2
apiVersion: v2
keywords:
- nginx-helm-chart
sources:
- https://github.com/CodeForPhilly/balancer-main
home: https://opencollective.com/code-for-philly/projects/balancer
2 changes: 2 additions & 0 deletions helm-chart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Chart initially created by Kompose from nginx-docker-compose.yml

54 changes: 54 additions & 0 deletions helm-chart/templates/frontend-static-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -c -f nginx-docker-compose.yml -o nginx-helm-chart
kompose.version: 1.31.2 (a92241f79)
creationTimestamp: null
labels:
io.kompose.service: frontend-static
name: frontend-static
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: frontend-static
strategy:
type: Recreate
template:
metadata:
annotations:
kompose.cmd: kompose convert -c -f nginx-docker-compose.yml -o nginx-helm-chart
kompose.version: 1.31.2 (a92241f79)
creationTimestamp: null
labels:
io.kompose.network/frontend-default: "true"
io.kompose.service: frontend-static
spec:
containers:
- env:
- name: CHOKIDAR_USEPOLLING
value: "true"
- name: VITE_API_BASE_URL
value: {{ .Values.VITE_API_BASE_URL }}

image: ghcr.io/codeforphilly/balancer-main/frontend-static:latest
name: frontend-static
ports:
- containerPort: 80
protocol: TCP
volumeMounts:
- mountPath: /etc/nginx/nginx.conf
name: nginx-conf
subPath: nginx.conf
readOnly: true
resources: {}
volumes:
- name: nginx-conf
configMap:
name: nginx-conf
items:
- key: nginx.conf
path: nginx.conf
restartPolicy: Always
status: {}
19 changes: 19 additions & 0 deletions helm-chart/templates/frontend-static-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -c -f nginx-docker-compose.yml -o nginx-helm-chart
kompose.version: 1.31.2 (a92241f79)
creationTimestamp: null
labels:
io.kompose.service: frontend-static
name: frontend-static
spec:
ports:
- name: "http"
port: 80
protocol: TCP
selector:
io.kompose.service: frontend-static
status:
loadBalancer: {}
Loading

0 comments on commit 140bc92

Please sign in to comment.