Coder Social home page Coder Social logo

Update images in docker hub about gatsby-docker HOT 8 OPEN

gatsbyjs avatar gatsbyjs commented on June 12, 2024 10
Update images in docker hub

from gatsby-docker.

Comments (8)

shicholas avatar shicholas commented on June 12, 2024 6

nice, thanks @ekeih fwiw here's my Dockerfile using Nginx.

ARG GATSBY_ACTIVE_ENV=production


FROM node:12-buster AS build

RUN yarn global add gatsby-cli
ARG GATSBY_ACTIVE_ENV
ENV GATSBY_ACTIVE_ENV=$GATSBY_ACTIVE_ENV

WORKDIR /app
ADD . ./
RUN yarn install
RUN gatsby build
RUN ls -la **/*

FROM nginx
COPY --from=build /app/public /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 80

and my nginx.conf

worker_processes    1;
user                nginx;

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"';

  keepalive_timeout  15;
  autoindex          off;
  server_tokens      off;
  port_in_redirect   off;
  sendfile           on;
  tcp_nopush         on;
  tcp_nodelay        on;

  client_max_body_size        64k;
  client_header_buffer_size   16k;
  large_client_header_buffers 4 16k;

  gzip             on;
  gzip_vary        on;
  gzip_proxied     any;
  gzip_types       application/javascript application/x-javascript application/rss+xml text/javascript text/css image/svg+xml;
  gzip_buffers     16 8k;
  gzip_comp_level  6;

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

  server {
    listen 80;
    server_name  neonlaw.com  www.neonlaw.com;

    autoindex off;
    charset utf-8;
    error_page 404 /usr/share/nginx/html/404.html;

    location / {
      if ($http_x_forwarded_proto = "http") {
        return 301 https://$server_name$request_uri;
      }

      root /usr/share/nginx/html;
      index index.html indx.htm;
    }

    location ~* \.(html)$ {
      if ($http_x_forwarded_proto = "http") {
        return 301 https://$server_name$request_uri;
      }

      root /usr/share/nginx/html;
      add_header Cache-Control "no-store";
      expires    off;
    }

    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|jsx|css|less|swf|eot|ttf|otf|woff|woff2|json)$ {
      if ($http_x_forwarded_proto = "http") {
        return 301 https://$server_name$request_uri;
      }

      root /usr/share/nginx/html;
      add_header Cache-Control "public";
      expires +1y;
    }

  }
}

You'll want to change the server_name instruction above. I have this setup to be like this repo and also redirect HTTP requests to HTTPS based on the X_FORWARDED_PROTO HTTP Header passed in from a load balancer (in my case GCP's Load Balancer).

from gatsby-docker.

ekeih avatar ekeih commented on June 12, 2024 2

In case anyone comes here looking for a solution. I wrote a short blog post about mine: https://fotoallerlei.com/blog/post/2020/dockerizing-a-gatsby-site/post

In case the post is offline in the future, the Dockerfile looks like this:

FROM node:13-buster-slim as build

WORKDIR /app
RUN yarn global add gatsby-cli && gatsby telemetry --disable
ADD package.json yarn.lock ./
RUN yarn --production --frozen-lockfile --non-interactive

ADD . ./
RUN gatsby build


FROM abiosoft/caddy:1.0.3-no-stats
RUN echo 'tls off' >> /etc/Caddyfile
COPY --from=build /app/public /srv

The second build stage can be replaced with nginx to be more similar to the original solution of this repo here.

from gatsby-docker.

rondondaniel avatar rondondaniel commented on June 12, 2024 1

Hello @ekeih excellent contribution! I read your post, and implementing as it is, it works perfect.
to run it after build ->
docker run --rm -p 2015:2015 "your image name here"
Thanks a lot

from gatsby-docker.

daydream05 avatar daydream05 commented on June 12, 2024 1

@shicholas thanks! I was able to fix it by removing that last location directive. Turns out .json is included on that.

from gatsby-docker.

ekeih avatar ekeih commented on June 12, 2024

When I tested it a few weeks ago, it seemed both tags, latest and onbuild, include the nginx container. So the onbuild step from the Readme fails because this tag doesn't include Gatsby at all.

from gatsby-docker.

KevinBurton avatar KevinBurton commented on June 12, 2024

In case anyone comes here looking for a solution. I wrote a short blog post about mine: https://fotoallerlei.com/blog/post/2020/dockerizing-a-gatsby-site/post

In case the post is offline in the future, the Dockerfile looks like this:

FROM node:13-buster-slim as build

WORKDIR /app
RUN yarn global add gatsby-cli && gatsby telemetry --disable
ADD package.json yarn.lock ./
RUN yarn --production --frozen-lockfile --non-interactive

ADD . ./
RUN gatsby build


FROM abiosoft/caddy:1.0.3-no-stats
RUN echo 'tls off' >> /etc/Caddyfile
COPY --from=build /app/public /srv

The second build stage can be replaced with nginx to be more similar to the original solution of this repo here.

I still get this warning
[2/4] Fetching packages...
warning [email protected]: Invalid bin field for "url-loader".

It still failes with:

COPY failed: stat /var/lib/docker/tmp/docker-builder102637302/nginx.conf: no such file or directory
error Command failed with exit code 1.
i

from gatsby-docker.

daydream05 avatar daydream05 commented on June 12, 2024

@shicholas hi, how do you set the cache-control for page-data.json to "public, max-age=0, must-revalidate" with that nginx setup?

from gatsby-docker.

shicholas avatar shicholas commented on June 12, 2024

@daydream05 you could add the string "public, max-age-0, must-revalidate" to this line https://github.com/NeonLaw/codebase/blob/development/docker/production.nginx.conf#L73

from gatsby-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.