GithubHelp home page GithubHelp logo

isabella232 / gatsby-docker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gatsbyjs/gatsby-docker

0.0 0.0 0.0 32 KB

Docker image that builds and hosts a Gatsby site

License: MIT License

Shell 91.75% Dockerfile 8.25%

gatsby-docker's Introduction

gatsbyjs/gatsby-docker Travis CI Build Status

Docker image that builds and hosts a Gatsby site.

Note: this is a community maintained project and doesn't yet have support for Gatsby v3 and beyond features like Functions, SSR, and DSG

This image has two major tags:

  1. latest - will serve your assets on production using up an nginx server

  2. onbuild - builds your project and creates a new docker image

Usage

  1. Create at the root of your project a Dockerfile and .dockerignore, as below: Dockerfile
    FROM gatsbyjs/gatsby:onbuild as build
    
    FROM gatsbyjs/gatsby
    COPY --from=build /app/public /pub
    .dockerignore
    .cache/
    node_modules/
    public/

    The first image is going to copy your project, install dependencies and build it.

  2. Build your project's docker image:
    docker build -t myproject/website .
  3. Upload to the registry
    docker push myproject/website
  4. Use it
    docker run --rm -p 80:80 myproject/website
    # Open your browser at http://localhost

Configuration

The way Nginx behaves can be configured using environment variables.

Please refer to the docker run command options for the --env-file flag where you can specify all required environment variables in a single file. This will save you from writing a potentially long docker run command. Alternatively you can use docker-compose.

Below is the complete list of available options that can be used to customize your Nginx configuration:

Environment variable Default Description
CACHE_IGNORE html Regular expression to specify which paths shouldn't be cacheable (header Cache-Control set to no-store).
CACHE_PUBLIC ico|jpg|jpeg|png|gif|svg|js|jsx|css|less|swf|eot|ttf|otf|woff|woff2 Regular expression to specify which paths should be cacheable (headers Cache-Control set to public and Expires set to the value of $CACHE_PUBLIC_EXPIRATION).
CACHE_PUBLIC_EXPIRATION 1y Time to set for header Expires. See http://nginx.org/en/docs/http/ngx_http_headers_module.html#expires
CHARSET utf-8 Charset being used in Content-Type response header field. See http://nginx.org/en/docs/http/ngx_http_charset_module.html
CUSTOM_SERVER_CONFIG Need to add some advanced/custom nginx config? No problem, you can inject through this environment variable. NOTE: would be discarded if /etc/nginx/server.conf is present.
DEBUG false If set to true the configuration is being printed before the server starts.
GZIP_LEVEL 6 Gzip compression level of a response. See http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_comp_level
GZIP_TYPES application/javascript application/x-javascript application/rss+xml text/javascript text/css image/svg+xml MIME types in addition to text/html for which gzip compression should be enabled. See http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_types
HTTP_PORT 80 The address and / or port for IP, or the path for a UNIX-domain socket on which the server will accept requests. See http://nginx.org/en/docs/http/ngx_http_core_module.html#listen
PUBLIC_PATH /pub The path to the directory from which files are being served. See http://nginx.org/en/docs/http/ngx_http_core_module.html#root
TRAILING_SLASH true Specifies if paths should end with a trailing slash or not. Prevents duplicated content by redirecting requests to URLs ending with a slash to its non-trailing-slash equivalent if set to true and the other way around for false.
WORKER_CONNECTIONS 1024 The maximum number of simultaneous connections that can be opened by a worker process. See http://nginx.org/en/docs/ngx_core_module.html#worker_connections
DISABLE_FILE_CACHE false Disables nginx's open file cache for when used with a network storage (NFS, SMB, etc)

Append rules for the server block in nginx config

You can mount a file to /etc/nginx/server.conf to extend the server block in nginx config. This could be useful if you have defined client-only routes in GatsbyJS. For example for client only rules on path /client-only the content of your mounted file should be like:

rewrite ^/client-only/([^.]*?/)$ /client-only/index.html;

Alternatively you can use a custom Dockerfile and copy the file on build:

FROM gatsbyjs/gatsby:latest
COPY nginx-server-rules.conf /etc/nginx/server.conf

NOTE: By adding the file /etc/nginx/server.conf, all the contents of the CUSTOM_SERVER_CONFIG environment variable will be discarded.

gatsby-docker's People

Contributors

aaaakshat avatar aslafy-z avatar cusspvz avatar grzegorz-wcislo avatar halkeye avatar jpavlicek avatar kanolato avatar kyleamathews avatar mfeltscher avatar oluwalogoye avatar rampantrami avatar rroslaniec avatar srijanprakash avatar torenware avatar

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.