I have this GitHub action job to build and publish Docker image to GitHub registry.
...
jobs:
push_to_registry:
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Push to GitHub Packages
uses: docker/build-push-action@v1
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
dockerfile: Dockerfile
registry: docker.pkg.github.com
repository: myrepo/myimg
tag_with_ref: true
However it is running at parent directory and my Dockerfile is inside app/.
.
|- .github/workflow/ci.yaml
|- README
|- app/
|- Dockerfile
|- package.json
|- package.lock.json
|- node_modules/
|- src/
|- ...
I tried setting working-directory:
working-directory: ./app
But still got the same error and I saw a forum post said it doesn't work well with uses.
How do I build Docker image inside sub-directory with GitHub action?
Edit 1
Reply to Edward's answer.
Yep, I tried it also. It found the correct Dockerfile, and I have to reset all location inside Dockerfile, such as COPY package*.json ./ to COPY ./app/package*.json ./. Problem is npm run build:
Step 12/28 : RUN npm run build
---> Running in 6986869d4bdf
> @myrepo/myapp@0.0.1 build /app
> rm -rf dist && tsc --build
error TS18003: No inputs were found in config file '/app/tsconfig.json'. Specified 'include' paths were '["src/**/*"]' and 'exclude' paths were '["dist"]'.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @myrepo/myapp@0.0.1 build: `rm -rf dist && tsc --build`
npm ERR! Exit status 1
This is my tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": ["node_modules/*", "types/*"]
}
},
"include": ["src/**/*"]
}
Seems like tsconfig.json also needs to be changed, "include": ["app/src/**/*"]. But it will all mess up my development workflow, because I'm running npm run dev inside app/.
Edit 2
path solves it. https://github.com/docker/build-push-action#path