website/blog/2024-07-14_moon-v1.27.mdx
In this release, we're adding improved Docker support, and a long-awaited task request.
<!--truncate-->In our last release, we introduced a new action pipeline that is more performant, accurate, and resilient, but was hidden behind an experimental flag. Since then, we've seen many users enable it successfully, and no issues have been reported! And with that, we're enabling the experiment by default.
If you run into an issue with this new pipeline, you can disable the experiment in
.moon/workspace.yml, like so. If you do encounter an issue, please report it to GitHub or Discord!
experiments:
actionPipelineV2: false
Since the beginning, tasks in moon have been modeled around a single command and its arguments; they are a 1-to-1 relationship. It was designed this way as it was a hard requirement for task inheritance to work correctly. If you have multiple tasks in the chain that need to be merged together, how will arguments be handled? Do they merge, overwrite, or replace? Do they prepend or append? Or maybe you want to keep the arguments but rename the binary/command itself? And many more such combinations.
But because of this limitation, tasks did not support executing multiple commands (via && or ;),
as this breaks argument merging (which command should the arguments belong too?). Tasks also did not
support redirects, pipes, and other shell scripting syntax. Over the year we've slowly tried to
support these in tasks, and while they technically do in some capacity, the experience is subpar.
To remedy this, we're introducing a new task field called script,
which is an alternative to command +
args. Scripts support everything mentioned above, and can be defined
as such (using a very contrived example).
tasks:
build:
script: 'rm -rf ./out && ./doBuild.sh out && ./genStats.sh > stats.json'
outputs:
- 'out'
--), while command/args do.:::info
For a full list of comparisons, and more information on commands vs scripts, head over to the official task documentation!
:::
As it turns out, a lot of moon users rely heavily on our Docker integration, which hasn't seen some love in quite a while. We felt it was time to change that.
moon docker file commandSince our release of Docker in moon (v0.15), we've provided an in-depth guide
on why our integration exists, and what it aims to solve. However, the guide required a bit of
manual non-trivial setup, which left users confused more than we like. To remedy this, we're
introducing a new command, moon docker file, which will generate a
multi-staged Dockerfile for a project.
To demonstrate this, here's what the Dockerfile looks like for our website.
#### BASE STAGE
#### Installs moon.
FROM node:latest AS base
WORKDIR /app
# Install moon binary
RUN curl -fsSL https://moonrepo.dev/install/moon.sh | bash
ENV PATH="/root/.moon/bin:$PATH"
#### SKELETON STAGE
#### Scaffolds repository skeleton structures.
FROM base AS skeleton
# Copy entire repository and scaffold
COPY . .
RUN moon docker scaffold website
#### BUILD STAGE
#### Builds the project.
FROM base AS build
# Copy toolchain
COPY --from=skeleton /root/.proto /root/.proto
# Copy workspace configs
COPY --from=skeleton /app/.moon/docker/workspace .
# Install dependencies
RUN moon docker setup
# Copy project sources
COPY --from=skeleton /app/.moon/docker/sources .
# Build the project
RUN moon run website:build
# Prune extraneous dependencies
RUN moon docker prune
#### START STAGE
#### Runs the project.
FROM base AS start
# Copy built sources
COPY --from=build /root/.proto /root/.proto
COPY --from=build /app /app
CMD moon run website:start
docker settingsTo further improve our Docker support, we're also introducing new docker settings to both
.moon/workspace.yml and
moon.yml. These settings allow you to customize the scaffold,
prune, and Dockerfile generation flows.
docker:
prune:
installToolchainDeps: false
scaffold:
include:
- '*.config.js'
docker:
file:
image: 'node:latest'
buildTask: 'build'
startTask: 'start'
View the official release for a full list of changes.
.moon/cache/schemas, so that they
can be dynamically created based on the current moon version and environment.