I want to create a custom Docker container Github action and started with this action.yml file
name: my-action
description: For testing purposes
branding:
icon: shield
color: green
inputs:
my-input:
description: demo
required: true
runs:
using: docker
image: Dockerfile
Next I added some code in a app.js file inside the root directory
const core = require('@actions/core');
try {
const myInput = core.getInput('my-input', { required: true });
core.notice(`Input is: ${myInput}`);
} catch (error) {
core.setFailed(error.message);
}
The Dockerfile
FROM node:16.13.0-alpine
USER node
WORKDIR /home/node
ADD --chown=node:node . /home/node
RUN npm install
CMD [ "node", "app.js" ]
To test my action I published my action and created a new workflow
name: Run the action
on: workflow_dispatch
jobs:
run-the-action:
runs-on: ubuntu-latest
steps:
- name: Run the action
uses: me/[email protected]
with:
my-input: hello
Unfortunately the action crashes with the error message
Error: Cannot find module '/github/workspace/app.js'
Maybe I'm missing a mapping from /home/node
to /github/workspace
? Does someone know what's wrong or how to fix it?
Please let me know if you need more information!
CodePudding user response:
This Dockerfile worked for me
FROM node:16.13.0-alpine
USER node
ADD --chown=node:node . /home/node
RUN cd /home/node && \
npm install --production
CMD [ "node", "/home/node/app.js" ]