Skip to content

Commit

Permalink
Fixing location and environment variable interpolation issues in the …
Browse files Browse the repository at this point in the history
…Docker Compose manifest and Gulpfile.
  • Loading branch information
adrianwebb committed Aug 28, 2024
1 parent e5c3fcf commit a5c8474
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 75 deletions.
2 changes: 2 additions & 0 deletions {{cookiecutter.project_slug}}/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
- ui
volumes:
- '.:/app:z'
- /app/node_modules
command: npm run dev
ports:
- '3000:3000'
Expand Down Expand Up @@ -98,6 +99,7 @@ services:
redis:
image: redis:6
container_name: '{{ cookiecutter.project_slug }}_redis'
command: /bin/sh -c "redis-server --requirepass $$REDIS_PASSWORD"
volumes:
- '{{ cookiecutter.project_slug }}_redis_data:/data'
env_file:
Expand Down
150 changes: 75 additions & 75 deletions {{cookiecutter.project_slug}}/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ const uglify = require('gulp-uglify-es').default;

// Relative paths function
function pathsConfig(appName) {
this.app = `./${pjson.name}`;
const vendorsRoot = 'node_modules';

return {
vendorsJs: [
`${vendorsRoot}/@popperjs/core/dist/umd/popper.js`,
`${vendorsRoot}/bootstrap/dist/js/bootstrap.js`,
],
app: this.app,
templates: `${this.app}/templates`,
css: `${this.app}/static/css`,
sass: `${this.app}/static/sass`,
fonts: `${this.app}/static/fonts`,
images: `${this.app}/static/images`,
js: `${this.app}/static/js`,
};
this.app = './app';
const vendorsRoot = 'node_modules';

return {
vendorsJs: [
`${vendorsRoot}/@popperjs/core/dist/umd/popper.js`,
`${vendorsRoot}/bootstrap/dist/js/bootstrap.js`,
],
app: this.app,
templates: `${this.app}/templates`,
css: `${this.app}/static/css`,
sass: `${this.app}/static/sass`,
fonts: `${this.app}/static/fonts`,
images: `${this.app}/static/images`,
js: `${this.app}/static/js`,
};
}

const paths = pathsConfig();
Expand All @@ -49,91 +49,91 @@ const paths = pathsConfig();

// Styles autoprefixing and minification
const processCss = [
autoprefixer(), // adds vendor prefixes
pixrem(), // add fallbacks for rem units
autoprefixer(), // adds vendor prefixes
pixrem(), // add fallbacks for rem units
];

const minifyCss = [
cssnano({ preset: 'default' }), // minify result
cssnano({ preset: 'default' }), // minify result
];

function project_styles() {
return src(`${paths.sass}/project.scss`)
.pipe(
sass({
importer: tildeImporter,
includePaths: [paths.sass],
}).on('error', sass.logError),
)
.pipe(plumber()) // Checks for errors
.pipe(postcss(processCss))
.pipe(dest(paths.css))
.pipe(rename({ suffix: '.min' }))
.pipe(postcss(minifyCss)) // Minifies the result
.pipe(dest(paths.css));
return src(`${paths.sass}/project.scss`)
.pipe(
sass({
importer: tildeImporter,
includePaths: [paths.sass],
}).on('error', sass.logError),
)
.pipe(plumber()) // Checks for errors
.pipe(postcss(processCss))
.pipe(dest(paths.css))
.pipe(rename({ suffix: '.min' }))
.pipe(postcss(minifyCss)) // Minifies the result
.pipe(dest(paths.css));
}

// Javascript minification
function scripts() {
return src([`${paths.js}/project.js`, `${paths.js}/*-page.js`])
.pipe(plumber()) // Checks for errors
.pipe(uglify()) // Minifies the js
.pipe(rename({ suffix: '.min' }))
.pipe(dest(paths.js));
return src([`${paths.js}/project.js`, `${paths.js}/*-page.js`])
.pipe(plumber()) // Checks for errors
.pipe(uglify()) // Minifies the js
.pipe(rename({ suffix: '.min' }))
.pipe(dest(paths.js));
}

// Vendor Javascript minification
function vendorScripts() {
return src(paths.vendorsJs, { sourcemaps: true })
.pipe(concat('vendors.js'))
.pipe(dest(paths.js))
.pipe(plumber()) // Checks for errors
.pipe(uglify()) // Minifies the js
.pipe(rename({ suffix: '.min' }))
.pipe(dest(paths.js, { sourcemaps: '.' }));
return src(paths.vendorsJs, { sourcemaps: true })
.pipe(concat('vendors.js'))
.pipe(dest(paths.js))
.pipe(plumber()) // Checks for errors
.pipe(uglify()) // Minifies the js
.pipe(rename({ suffix: '.min' }))
.pipe(dest(paths.js, { sourcemaps: '.' }));
}

// Run django server
function runServer(cb) {
const cmd = spawn('python', ['manage.py', 'runserver'], { stdio: 'inherit' });
cmd.on('close', function (code) {
console.log('runServer exited with code ' + code);
cb(code);
});
const cmd = spawn('python', ['manage.py', 'runserver'], { stdio: 'inherit' });
cmd.on('close', function (code) {
console.log('runServer exited with code ' + code);
cb(code);
});
}

// Browser sync server for live reload
function initBrowserSync() {
browserSync.init(
[`${paths.css}/*.css`, `${paths.js}/*.js`, `${paths.templates}/*.html`],
{
// https://www.browsersync.io/docs/options/#option-open
// Disable as it doesn't work from inside a container
open: false,
// https://www.browsersync.io/docs/options/#option-proxy
proxy: {
target: 'ui:8000',
proxyReq: [
function (proxyReq, req) {
// Assign proxy 'host' header same as current request at Browsersync server
proxyReq.setHeader('Host', req.headers.host);
},
],
},
// https://browsersync.io/docs/options/#option-notify
notify: false,
},
);
browserSync.init(
[`${paths.css}/*.css`, `${paths.js}/*.js`, `${paths.templates}/*.html`],
{
// https://www.browsersync.io/docs/options/#option-open
// Disable as it doesn't work from inside a container
open: false,
// https://www.browsersync.io/docs/options/#option-proxy
proxy: {
target: 'ui:8000',
proxyReq: [
function (proxyReq, req) {
// Assign proxy 'host' header same as current request at Browsersync server
proxyReq.setHeader('Host', req.headers.host);
},
],
},
// https://browsersync.io/docs/options/#option-notify
notify: false,
},
);
}

// Watch
function watchPaths() {
watch(`${paths.sass}/*.scss`, project_styles);
watch(`${paths.templates}/**/*.html`).on('change', reload);
watch([`${paths.js}/*.js`, `!${paths.js}/*.min.js`], scripts).on(
'change',
reload,
);
watch(`${paths.sass}/*.scss`, project_styles);
watch(`${paths.templates}/**/*.html`).on('change', reload);
watch([`${paths.js}/*.js`, `!${paths.js}/*.min.js`], scripts).on(
'change',
reload,
);
}

// Generate all assets
Expand Down

0 comments on commit a5c8474

Please sign in to comment.