In this exercise we learn how to configure inputs
for tasks in nx.
We currently have a problem. Take a look at the deploy
target of the movies
app. It has a dependency
to the tools/deploy/frontend.Dockerfile
.
If you do any change to the frontend.Dockerfile
, the deploy
command won't be affected at all.
Change to tools/deploy/frontend.Dockerfile
FROM nginx:1.21.4-alpine
ARG APP_NAME
RUN adduser -D -g 'www' www
COPY tools/deploy/nginx.conf /etc/nginx/nginx.conf
COPY dist/apps/$APP_NAME/browser /usr/share/nginx/html
# this is just a comment 👈️ should be enough
CMD ["nginx", "-g", "daemon off;"]
EXPOSE 80
You can confirm bey either watching the affected task graph
or actually run the affected:deploy
command.
Tip
Please confirm that your git is currently clean. You should not have other changes locally
Affected Task Graph
nx affected -t deploy --graph
The missing piece are of course the right inputs for the task.
First, create a section namedSections
that has a configuration for
a dockerFiles
input that points to the dockerfile we are using for the deployment.
Go to the project.json
of the movies
app.
Configure namedInputs
// apps/movies/project.json
{
"namedInputs": {
"dockerFiles": ["{workspaceRoot}/tools/deploy/frontend.Dockerfile"]
},
}
Configure the deploy
target of the movies
app so that it uses the newly created namedInputs
.
We want to make it right directly in the beginning, so please also add the following options to the inputs
:
{ "dependentTasksOutputFiles": "**/dist/**/*", "transitive": true }
use the namedInputs in the target
{
"inputs": [
"dockerFiles",
{ "dependentTasksOutputFiles": "**/dist/**/*", "transitive": true }
],
}
Now you should commit only the project.json
so that your branch is again clean, but the changes you've
done to the .Dockerfile
git add apps/movies/project.json
git commit -m "fix inputs for deploy target"
Now the deploy
target should be affected when there is a change to the .Dockerfile
.