Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnuma committed Aug 24, 2021
1 parent deeceef commit 46ccb1a
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.cache/
node_modules/
public/
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:12-buster as build
RUN yarn global add gatsby-cli
WORKDIR /app
ADD pie-website ./
RUN yarn
RUN gatsby build

#Copy the built website over
FROM nginx:1.19.7
EXPOSE 80

# Configure Nginx for http basic auth
COPY nginx/prod-nginx.conf /etc/nginx/nginx.conf

# Add website contents
COPY --from=build /app/public /usr/share/nginx/html

CMD nginx -g 'daemon off;'
17 changes: 17 additions & 0 deletions Dockerfile.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM gatsbyjs/gatsby:onbuild as build

#Copy the built website over
FROM nginx:1.19.7
EXPOSE 80

# Configure Nginx for http basic auth
COPY nginx/staging-nginx.conf /etc/nginx/nginx.conf
COPY nginx/http-basic-auth-start.sh /etc/nginx/http-basic-auth-start.sh

# Add website contents
COPY --from=build /app/public /usr/share/nginx/html

# Prevent web scrapers
RUN echo "User-agent: * Disallow: /" > /usr/share/nginx/html/robots.txt

CMD /etc/nginx/http-basic-auth-start.sh
18 changes: 18 additions & 0 deletions nginx/http-basic-auth-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# Run the nginx server with http basic auth configured via env vars

# Err if http basic auth is not configured via $HTPASSWD
if [[ -z "$HTPASSWD" ]]; then
echo "Must set HTPASSWD in environment" 1>&2
exit 1
fi

# Copy http basic auth from env to file system
# $HTPASSWD contains the content of the file generated by htpasswd
mkdir /usr/share/nginx/auth
echo $HTPASSWD > /usr/share/nginx/auth/.htpasswd
echo "added .htpasswd to enable http basic auth"

echo "starting nginx"
nginx -g 'daemon off;'

46 changes: 46 additions & 0 deletions nginx/prod-nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;

keepalive_timeout 65;

gzip on;

server {
listen 80;
server_name localhost;

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

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

}

48 changes: 48 additions & 0 deletions nginx/staging-nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;

keepalive_timeout 65;

gzip on;

server {
listen 80;
server_name localhost;

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

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

auth_basic "PiE Website Staging";
auth_basic_user_file "/usr/share/nginx/auth/.htpasswd";
}

0 comments on commit 46ccb1a

Please sign in to comment.