Skip to content

Commit 140bc92

Browse files
Merge pull request #66 from CodeForPhilly/develop
Release: v0.1.1
2 parents aef6135 + c657730 commit 140bc92

17 files changed

+320
-29
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: 'Containers: Publish'
2+
3+
on:
4+
push:
5+
tags: [ 'v*' ]
6+
7+
8+
jobs:
9+
release-containers:
10+
name: Build and Push
11+
runs-on: ubuntu-latest
12+
steps:
13+
14+
- uses: actions/checkout@v3
15+
16+
- name: Login to ghcr.io Docker registry
17+
uses: docker/login-action@v2
18+
with:
19+
registry: ghcr.io
20+
username: ${{ github.repository_owner }}
21+
password: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- name: Compute Docker container image addresses
24+
run: |
25+
DOCKER_REPOSITORY="ghcr.io/${GITHUB_REPOSITORY,,}"
26+
DOCKER_TAG="${GITHUB_REF:11}"
27+
28+
echo "DOCKER_REPOSITORY=${DOCKER_REPOSITORY}" >> $GITHUB_ENV
29+
echo "DOCKER_TAG=${DOCKER_TAG}" >> $GITHUB_ENV
30+
31+
echo "Using: ${DOCKER_REPOSITORY}/*:${DOCKER_TAG}"
32+
33+
# - name: 'Pull previous Docker container image: :latest'
34+
# run: docker pull "${DOCKER_REPOSITORY}:latest" || true
35+
36+
- name: 'Pull previous Docker container image: frontend-static:latest'
37+
run: docker pull "${DOCKER_REPOSITORY}/frontend-static:latest" || true
38+
39+
- name: 'Build Docker container image: frontend-static:latest'
40+
run: |
41+
docker build \
42+
--cache-from "${DOCKER_REPOSITORY}/frontend-static:latest" \
43+
--file frontend/Dockerfile.demo \
44+
--build-arg SERVER_NAME=localhost \
45+
--tag "${DOCKER_REPOSITORY}/frontend-static:latest" \
46+
--tag "${DOCKER_REPOSITORY}/frontend-static:${DOCKER_TAG}" \
47+
frontend
48+
- name: 'Push Docker container image frontend-static:latest'
49+
run: docker push "${DOCKER_REPOSITORY}/frontend-static:latest"
50+
51+
- name: 'Push Docker container image frontend-static:v*'
52+
run: docker push "${DOCKER_REPOSITORY}/frontend-static:${DOCKER_TAG}"
53+
#
54+
#
55+
# - name: 'Build Docker container image: backend:latest'
56+
# run: |
57+
# cd backend && \
58+
# make && \
59+
# docker image tag "${DOCKER_REPOSITORY}/backend/local:latest" "${DOCKER_REPOSITORY}/backend:latest"
60+
#
61+
# - name: Push Docker container image backend:latest
62+
# run: docker push "${DOCKER_REPOSITORY}/backend:latest"
63+
#
64+
# - name: Push Docker container image backend:v*
65+
# run: docker push "${DOCKER_REPOSITORY}/backend:${DOCKER_TAG}"
66+
67+
# - name: Push Docker container image :v*"
68+
# run: docker push "${DOCKER_REPOSITORY}:${DOCKER_TAG}"
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
# This image runs the production server, with nginx
12
###########
23
# BUILDER #
34
###########
45

56
# pull official base image
6-
FROM python:3.11.4-slim-buster as builder
7+
FROM python:3.11.4-slim-buster as python_builder
78

89
# set work directory
910
WORKDIR /usr/src/app
@@ -48,8 +49,8 @@ WORKDIR $APP_HOME
4849

4950
# install dependencies
5051
RUN apt-get update && apt-get install -y --no-install-recommends netcat
51-
COPY --from=builder /usr/src/app/wheels /wheels
52-
COPY --from=builder /usr/src/app/requirements.txt .
52+
COPY --from=python_builder /usr/src/app/wheels /wheels
53+
COPY --from=python_builder /usr/src/app/requirements.txt .
5354
RUN pip install --upgrade pip
5455
RUN pip install --no-cache /wheels/*
5556

@@ -69,3 +70,6 @@ USER app
6970

7071
# run entrypoint.prod.sh
7172
ENTRYPOINT ["/home/app/web/entrypoint.prod.sh"]
73+
74+
75+
# TODO: gunicorn stuff
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services:
1212
build: ./server
1313
command: python manage.py runserver 0.0.0.0:8000
1414
volumes:
15-
- ./server:/usr/src/server
15+
- ./server:/usr/src/app
1616
ports:
1717
- "8000:8000"
1818
env_file:
@@ -23,9 +23,10 @@ services:
2323
image: balancer-frontend
2424
build:
2525
context: frontend
26-
dockerfile: Dockerfile
26+
dockerfile: Dockerfile.dev
2727
args:
2828
- IMAGE_NAME=balancer-frontend
29+
- FRONTEND_VERSION=0.0.1
2930
ports:
3031
- "3000:3000"
3132
environment:

docker-compose.prod.yml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
volumes:
66
- postgres_data:/var/lib/postgresql/data/
77
env_file:
8-
- ./.env.prod.db
8+
- ./config/env/env.prod.db
99
backend:
1010
build:
1111
context: ./server
@@ -14,22 +14,9 @@ services:
1414
ports:
1515
- 8000:8000
1616
env_file:
17-
- ./config/env/.env.prod
17+
- ./config/env/env.prod
1818
depends_on:
1919
- db
20-
frontend:
21-
image: balancer-frontend
22-
build:
23-
context: frontend
24-
dockerfile: Dockerfile
25-
args:
26-
- IMAGE_NAME=balancer-frontend
27-
ports:
28-
- "3000:3000"
29-
environment:
30-
- CHOKIDAR_USEPOLLING=true
31-
depends_on:
32-
- backend
3320

3421
volumes:
3522
postgres_data:

frontend/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,3 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25-
26-
.DS_Store

frontend/Dockerfile.demo

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This dockerfile builds an image for a static frontend only server suitable for online hosting.
2+
# Use the official Node.js image as the base image
3+
FROM node:18 as builder
4+
5+
# Set the working directory inside the container
6+
WORKDIR /usr/src/app
7+
8+
# Copy package.json and package-lock.json
9+
COPY package*.json ./
10+
11+
# Set version number
12+
ARG FRONTEND_VERSION
13+
RUN npm version $FRONTEND_VERSION
14+
15+
# Install dependencies
16+
RUN npm ci --legacy-peer-deps
17+
18+
# Copy project files
19+
COPY . .
20+
21+
RUN npm run build
22+
23+
FROM alpine:latest as nginx-config
24+
RUN apk --no-cache add gettext
25+
WORKDIR /app
26+
COPY nginx.conf.demo ./nginx.conf.demo
27+
# This will get overwritten by helm chart
28+
29+
ARG SERVER_NAME
30+
ENV SERVER_NAME $SERVER_NAME
31+
RUN cat nginx.conf.demo | envsubst > nginx.conf
32+
33+
FROM nginx:alpine
34+
35+
COPY --from=nginx-config /app/nginx.conf /etc/nginx/nginx.conf
36+
COPY --from=Builder /usr/src/app/dist /usr/share/nginx/html
37+
38+
# The default entrypoint works for us.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Use the official Node.js 14 image as the base image
1+
# This dockerfile builds an image for a Vite development server
2+
# Use the official Node.js image as the base image
23
FROM node:18
34

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

1617
# Build the project
17-
RUN npm run build
18+
# RUN npm run build
1819

1920
# Expose a port if required
20-
EXPOSE 3000
21+
# EXPOSE 3000
2122

22-
# Start the application
23+
# Start the dev server
2324
CMD [ "npm", "run", "dev" ]
2425

2526
# Set the image name

frontend/docker-compose.demo.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: "3.8"
2+
services:
3+
frontend-static:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile.demo
7+
args:
8+
- IMAGE_NAME=frontend-static
9+
- FRONTEND_VERSION=0.0.2
10+
- SERVER_NAME=localhost
11+
image: ghcr.io/codeforphilly/balancer-main/frontend-static:0.0.2
12+
ports:
13+
- "80:80"
14+
environment:
15+
- CHOKIDAR_USEPOLLING=true
16+
- VITE_API_BASE_URL=https://devnull-as-a-service.com/dev/null
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ services:
33
react-app:
44
build:
55
context: .
6-
dockerfile: Dockerfile
6+
dockerfile: Dockerfile.dev
77
args:
8-
- IMAGE_NAME=balancer-frontend
8+
- IMAGE_NAME=balancer-frontend-dev
99
ports:
1010
- "3000:3000"
11+
# The port number is hard-coded, located in ./vite.config.ts
1112
environment:
1213
- CHOKIDAR_USEPOLLING=true
1314
volumes:
1415
- "./:/usr/src/app:delegated"
15-
- "/usr/src/app/node_modules/"
16+
- "./node_modules:/usr/src/app/node_modules/"

frontend/nginx.conf.demo

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# nginx config file for static frontend demo site.
2+
# This will be the nginx.conf in the docker image before it gets overwritten by kubernetes helm chart.
3+
user nginx;
4+
worker_processes 1;
5+
events {
6+
worker_connections 1024;
7+
}
8+
http {
9+
include /etc/nginx/mime.types;
10+
server {
11+
listen 80;
12+
listen [::]:80;
13+
server_name $SERVER_NAME;
14+
15+
location / {
16+
root /usr/share/nginx/html;
17+
index index.html index.htm;
18+
}
19+
20+
#error_page 404 /404.html;
21+
22+
# redirect server error pages to the static page /50x.html
23+
#
24+
error_page 500 502 503 504 /50x.html;
25+
location = /50x.html {
26+
root /usr/share/nginx/html;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)