Public | Automated Build

Last pushed: 3 days ago
Short Description
Starting point for setting up a static site build environment using Hugo and Gulp.
Full Description

Supported tags

  • latest

About this image

This image is meant to be a starting point for setting up a static site build environment using Hugo and Gulp.

The image does export port 80 to serve the site for development purposes.

It has a volume defined to contain the source files for live reload at /usr/src.

This image does setup a Docker entrypoint to save some time when invoking Hugo commands.
Therefore the entrypoint checks for the first argument:

  • bash starts a bash environment for container debugging
  • build invokes gulp build
  • server invokes gulp server (will be invoked by default because server is set as CMD)

If none of these match all arguments are passed to the hugo command.

How to use this image

##Using the onbuild image

docker-compose.yml

static:
    build: static
    ports:
        - "80:80"
    volumes:
        - ./static/src:/usr/src
    environment:
        - B2D_IP=192.168.99.100

static/Dockerfile

FROM alang/hugo_gulp

static/package.json

{
  "name": "build",
  "version": "1.0.0",
  "private": true,
  "devDependencies": {
    "browser-sync": "2.11.1",
    "del": "2.2.0",
    "gulp": "3.9.0",
    "gulp-util": "3.0.7"
  }
}

static/gulpfile.js

const browserSync = require('browser-sync');
const childProcess = require('child_process');
const del = require('del');
const gulp = require('gulp');
const util = require('gulp-util');

const SOURCE_DIR = '/usr/src';
const PUBLIC_DIR = SOURCE_DIR + '/public';

function hugoBuild(baseURL) {
    const cmd = [
        'hugo',
        '--source=' + SOURCE_DIR,
        '--verbose'
    ];

    if (baseURL !== undefined) {
        cmd.push('--baseURL=' + baseURL);
    }

    const result = childProcess.execSync(cmd.join(' '), {encoding: 'utf-8'});
    util.log(`Hugo:\n${result}`);
}

gulp.task('hugo', () => {
    hugoBuild();
});

gulp.task('hugo:b2d', () => {
    hugoBuild('http://' + process.env.B2D_IP);
});

gulp.task('clean', () => {
    del.sync(
        [PUBLIC_DIR + '/**', '!' + PUBLIC_DIR],
        {force: true}
    );
});

gulp.task('build', ['clean', 'hugo']);

gulp.task('server', ['clean', 'hugo:b2d'], () => {
    browserSync({
        server: {
            baseDir: PUBLIC_DIR
        },
        files: PUBLIC_DIR,
        port: 80,
        open: false,
        host: '0.0.0.0'
    });
    gulp.watch([SOURCE_DIR + '/**', '!' + PUBLIC_DIR + '/**'], ['clean', 'hugo:b2d']);
});

Execute commands

Some example commands:

  • create Hugo site docker-compose run static new site /usr/src
  • run development server: docker-compose up
  • create new Hugo content: docker-compose run static new post/first.md
  • create final assets: docker-compose run static build

User Feedback

Issues

If you have any problems with or questions about this image, please contact me through a GitHub issue.

Contributing

You are invited to contribute new features, fixes, or updates, large or small.
Please send me a pull request.

Docker Pull Command
Owner
alang
Source Repository

Comments (0)