Is there a way to include a lockfile in a docker container as an optional step?

I am attempting to create a docker image that can optionally incorporate a yarn or npm lockfile during the build process. I want to include it explicitly, but also ensure that the build does not fail if the lockfile is missing.

The goal is to respect deterministic build processes used by hosted applications without enforcing them. Additionally, I aim to allow applications to utilize this container for establishing deterministic builds.

Below is my initial setup:

FROM node:8.12.0-alpine
USER node
WORKDIR ${my_workdir}
COPY --chown=node:node src/yarn.lock ./
COPY --chown=node:node src/package*.json ./
RUN yarn && yarn cache clean
COPY --chown=node:node src/ .
CMD []

Is there a specific command or option I could implement instead of 'copy' that will not cause an error if the 'src/yarn.lock' file is missing from the filesystem?

Answer №1

If you're encountering issues with the COPY command failing, one possible solution is to include the yarn.lock file as yarn.lock* alongside another file. Here's an example of how you can modify your Dockerfile to address this issue:

FROM node:8.12.0-alpine
USER node
WORKDIR ${my_workdir}
COPY --chown=node:node src/package*.json src/yarn.lock* ./
RUN yarn && yarn cache clean
COPY --chown=node:node src/ .
CMD []

I hope this suggestion proves helpful!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can we have a div stay at the top of the screen when scrolling down, but return to its original position when scrolling back up?

By utilizing this code, a div with position: absolute (top: 46px) on a page will become fixed to the top of the page (top: 0px) once the user scrolls to a certain point (the distance from the div to the top of the page). $(window).scroll(function (e) { ...

Is there a way to alter the CSS padding class for collapsed elements?

I've created a navbar by following Bootstrap's tutorial, but I'm facing an issue with the padding. I used the Bootstrap class "pe-5" to add padding to a form within the navbar so that it aligns to the right with some space from the screen ed ...

What is causing the error when trying to parse a JSON with multiple properties?

Snippet: let data = JSON.parse('{"name":"dibya","company":"wipro"}'); Error Message : An error occurred while trying to parse the JSON data. The console displays "Uncaught SyntaxError: Unexpected end of JSON input" at line 1, character 6. ...

Guide to setting up sub-routes in fastify

Currently, I am incorporating fastify as the web framework for my nodejs project. My aim is to organize and call all routes from a specific directory while having a base route established in the main JS file, similar to how it's done in express. Despi ...

The creation of a contract through the 'npx thirdweb@latest create' command is encountering

Whenever I attempt to execute the command, it results in an error occurring. EINVAL: invalid argument, mkdir 'C:\Users\fahim\AppData\Local\Temp\fahim\if-you-need-to-delete-this-open-an-issue-sync-disk-cache\thir ...

Setting up the initial 3 parameters in a v-for loop

What is the best way to begin a v-for loop? For instance, we have an array named "array" with the following values: array = [dog, cat, e, f, g]; I am interested in using a v-for loop that will start looping through and only consider the first 3 values. ...

Is it possible to update the content page without having to refresh the master page?

Our website features a Master page with main menu options and corresponding sub menus. When a user clicks on a main menu item, the relevant sub menus should be displayed. After clicking on a sub menu, the content page should update without having to refr ...

Is it necessary to incorporate express in a Next.js project?

I'm currently working on a website using Next.js. With Next.js, I have access to features like SSR and dynamic routing. Is it necessary for me to incorporate express into my project? If yes, what are the reasons behind needing to use it? What unique ...

Sending an identifier to a PHP file using JavaScript

I am facing an issue with my JavaScript code where the id is supposed to be passed to my PHP script at intervals, but if the id stops being passed (indicating that the user has closed the JavaScript page), a specific block in the if statement should run in ...

Using jQuery, you can submit a form easily

In my work with Django, I am developing a quiz web application that requires a form submission after answering each question. The questions are displayed correctly, but I am facing an issue when trying to submit the form with the answers. The answers to t ...

Harness the power of npm to execute tests across various directories with the help of wildcards

Whenever I execute this command "test": "mocha *.spec.js *.test.js test/*.spec.js test/*.test.js", It functions as expected, running all the test and spec files in the root directory (2) along with any in the test/ directory (2). In total, 4 tests are ex ...

Dealing with the Spread operator in React and Redux causes issues

As a newcomer to the world of React and Redux, I find myself facing compilation errors while working on a reducer due to my attempt to utilize the spread operator. export default function chaptersReducer( state = { chapters: {}, isFetching: false, error ...

Implement the Vue.js @click directive in a location outside of an HTML element

I've set up a link like this: <a href="#" @click="modal=true">Open modal</a> Here's the data setup: export default { data () { return { modal: false } } } Is there a way to trigger the cli ...

JavaScript array displaying excess whitespace in its presentation

https://i.sstatic.net/5AdA7.png One issue I am facing is that when I use console.log(a), it adds extra spaces which then flow through to the backend. This leads to each element breaking after the first one. How can I resolve this problem and why does it o ...

How can I implement conditional rendering with React on a div element?

Is it possible to implement conditional rendering by simply adding the boolean checked isVisible=true onto the div? Will this ensure that it only renders when true? Could there be any potential issues with the component's state changing after renderi ...

Storing Ember.js Views for Faster Loading

Exploring the features of AngularJS and Ember, I am curious to know if Ember has the capability to cache views instead of just loading/reloading them. For instance, if I have tabs with templates like "abc.html," "def.html," and "ghi.html," can I create div ...

The AngularJS framework is not effectively generating the desired table structure

EDIT 1 - Here is a Plnkr example that demonstrates the issue - http://plnkr.co/edit/qQn2K3JtSNoPXs9vI7CK?p=preview ---------------- ORIGINAL CODE AND PROBLEM ---------------- I've been using the angular datatable library (angular-datatables) to g ...

react-responsive-carousel: setting a specific height for thumbnail images

After setting a fixed height for the image, I noticed that the same height is also being applied to the thumbnails. How can I avoid this issue? <Carousel width="600px" dynamicHeight={false}> {data?.book?.images.map((image, i) => ( ...

Universal customization for Material-UI Select

I am attempting to customize the appearance of a select component within a React project using MUI 5. Specifically, I want to modify the border size and color when the select component is in focus. While other components can be styled globally using styleO ...

The DataType.MultilineText field in my modal popup partial view is causing all validation to fail

I encountered a peculiar issue recently. After creating a new asp.net mvc5 application, I decided to upgrade it to asp.net mvc-5.2.2. The problem arose with the following field:- [Required] [StringLength(200)] public string Name { get; set; } When ren ...