Browse Source

Added capability to use private git repos as dep srcs

master
Brandon Nolet 9 months ago
parent
commit
5221d26922
4 changed files with 64 additions and 9 deletions
  1. +22
    -4
      Dockerfile
  2. +7
    -2
      README.md
  3. +30
    -1
      build.sh
  4. +5
    -2
      docker-compose.yml

+ 22
- 4
Dockerfile View File

@@ -1,16 +1,34 @@
FROM node:12-alpine

RUN mkdir /script

COPY build.sh /script/
# Add git and ssh utilities
RUN apk add git
RUN apk add openssh

# Create directory for ssh keys
RUN mkdir /root/.ssh

# Add common known hosts
# Can be overwritten if user already has known_hosts
# File mounted in volume
RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
RUN ssh-keyscan gitlab.com >> /root/.ssh/known_hosts

# copy over build script and make executable
RUN mkdir /script
COPY build.sh /script/
RUN chmod +x /script/build.sh

RUN npm install -g gatsby-cli
# install gatsby utils
RUN npm install -g gatsby-cli gatsby

# set up environment
RUN mkdir /src
RUN mkdir /staging
RUN mkdir /public

WORKDIR /src
# change dir
WORKDIR /staging

# make container run build script on creation
CMD [ "/script/build.sh" ]

+ 7
- 2
README.md View File

@@ -1,3 +1,6 @@
**Note: This container will be using your ssh keys. If you value your security, build this
container yourself.**

# Gatsby Builder

This docker container will take your source Gatsby site files and output the deployment-ready static site files pulling from and writing to your desired directories. These directories are configurable from docker compose.
@@ -23,6 +26,8 @@ You can find these values by entering `id -u` and `id -g` in your terminal. This

Modify `docker-compose.yml` to have the `./src` and `./public` volumes point to your desired folder. For example, if your source files are located in `/home/user/hello-world` then that is what you would set the source volume to: `- /home/user/hello-world:/src`. You can set the `/public` directory to be mapped to a host folder in a similar fashion. The `public` folder is that which will hold the static site files (html, css, js).

# Building
If you're not pulling from private repos with `npm install` then you can remove the ssh key line from the `volumes` section. Otherwise, set the source directory as that which your `id_rsa` and `id_rsa.pub` files are located in. This will also use your `known_hosts` file if you have one.

# Building Your Gatsby Project

Once you've set up your environment, simply run `docker-compose up` from the `gatsby-builder` directory in which the modified `docker-compose.yml` file resides. The static site files will be deposited in your target folder and should be fully accessible to you.
Once you've set up your environment, simply run `docker-compose up` from the `gatsby-builder` directory in which the modified `docker-compose.yml` file resides. The static site files will be deposited in your target folder and should be fully accessible to you.

+ 30
- 1
build.sh View File

@@ -1,7 +1,36 @@
#!/bin/sh

# copy source to staging area so node_modules
# isn't written to host directory
cp -R /src/* /staging/
cd /staging

# copy pre-installed v of gatsby to staging
# node_modules directory
mkdir -p node_modules/gatsby
cp -R /usr/local/lib/node_modules/gatsby/* /staging/node_modules/gatsby


# copy and correct perms for user's ssh key
cp -R /tmp/.ssh/* /root/.ssh/

chmod 700 /root/.ssh
chmod 644 /root/.ssh/id_rsa.pub
chmod 600 /root/.ssh/id_rsa

# add ssh key to ssh-agent so npm can use it
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

# install project deps
npm install

# build the project
gatsby build

cp -R /src/public/* /public
# copy static files to mounted output dir
cp -R /staging/public/* /public

# correct permissions using values from
# .env file
chown -R $USERID:$GROUPID /public

+ 5
- 2
docker-compose.yml View File

@@ -4,11 +4,14 @@ version: '3'
services:

gatsby-builder:
image: gatsby-builder:latest #1.0.1 as of this commit
image: bnolet/gatsby-builder:latest #1.1.0 as of this commit
container_name: gatsby-builder
volumes:
- ./src:/src # `./src` Should be set to the directory your gatsby source is in
- ./src:/src # `./src` Should be set to the directory your gatsby project is in
- ./public:/public # `./public` can be set to whatever directory you wish it to be
# used for output directory
- ~/.ssh:/tmp/.ssh:ro # used if you're pulling from a private npm/git repo w/ npm
# install
env_file: .env # create this file where you'll be running `docker-compose up` from
# put inside the following:
# USERID=<your-uid>


Loading…
Cancel
Save