diff --git a/README.md b/README.md index a22184b..1b262a3 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,8 @@ The action comes with additional options that you can use to configure your proj | usedocker | false | Will deploy using Dockerfile in project root | true or false | | docker_heroku_process_type | false | Type of heroku process (web, worker, etc). This option only makes sense when usedocker enabled. Defaults to "web" (Thanks to [singleton11](https://github.com/singleton11) for adding this feature) | web, worker | | docker_build_args | false | A list of args to pass into the Docker build. This option only makes sense when usedocker enabled. | NODE_ENV | +| docker_context_path | false | Path to use as build context (defaults to Dockerfile dir). This option only makes sense when usedocker enabled. | ./src, ./backend | +| docker_find_recursive | false | Pushes Dockerfile. found in current and subdirectories. This option only makes sense when usedocker enabled. | true or false | | appdir | false | Set if your app is located in a subdirectory | api, apis/python | | healthcheck | false | A URL to which a healthcheck is performed (checks for 200 request) | https://demo-rest-api.herokuapp.com | | checkstring | false | Value to check for when conducting healthcheck requests | ok | @@ -182,6 +184,73 @@ jobs: Also, thanks to [Olav Sundfør](https://github.com/olaven) for adding the Docker feature and [Matt Stavola](https://github.com/mbStavola) for adding the ability to pass in build args. +#### Deploy with Docker Context Path + +If your Dockerfile is not located in the root directory or you need to specify a custom build context (the root in case of a monorepo), you can use the `docker_context_path` option: + +_.github/workflows/main.yml_ + +```yaml +name: Deploy + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Heroku CLI + run: | + curl https://cli-assets.heroku.com/install.sh | sh + - uses: akhileshns/heroku-deploy@v3.14.15 + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: "YOUR APP's NAME" + heroku_email: "YOUR EMAIL" + usedocker: true + docker_context_path: "." + docker_find_recursive: true + docker_heroku_process_type: "worker" # Specify the process type if needed +``` + +#### Deploy with Multiple Docker Processes (Recursive) + +To deploy multiple Docker containers from different subdirectories (using `Dockerfile.web`, `Dockerfile.worker`, etc.), use the `docker_find_recursive` option: + +_.github/workflows/main.yml_ + +```yaml +name: Deploy + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Heroku CLI + run: | + curl https://cli-assets.heroku.com/install.sh | sh + - uses: akhileshns/heroku-deploy@v3.14.15 + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: "YOUR APP's NAME" + heroku_email: "YOUR EMAIL" + usedocker: true + docker_find_recursive: true + docker_heroku_process_type: "web worker" +``` + +This will look for `Dockerfile.web` and `Dockerfile.worker` in the current directory and subdirectories. + ### Deploy with custom Buildpacks Taken from the official heroku website: @@ -679,6 +748,8 @@ jobs: - For more info on how Heroku enables deployment using Docker, check out [https://www.heroku.com/deploy-with-docker](https://www.heroku.com/deploy-with-docker) +- For more information about Docker container deployment options, including `docker_context_path` and `docker_find_recursive`, see the [Heroku Container Registry & Runtime documentation](https://devcenter.heroku.com/articles/container-registry-and-runtime) + ## License This project is licensed under the MIT License - see the [LICENSE](https://github.com/AkhileshNS/heroku-deploy/blob/master/LICENSE) file for details diff --git a/action.yml b/action.yml index c91445b..3085fd7 100644 --- a/action.yml +++ b/action.yml @@ -39,6 +39,14 @@ inputs: docker_build_args: description: "A list of args to pass into the Docker build. This option only makes sense when usedocker enabled" required: false + docker_context_path: + description: "Path to use as build context (defaults to Dockerfile dir). This option only makes sense when usedocker enabled" + required: false + default: "" + docker_find_recursive: + description: "Pushes Dockerfile. found in current and subdirectories. This option only makes sense when usedocker enabled" + required: false + default: "false" appdir: description: "Set if your app is located in a subdirectory." default: "" diff --git a/index.js b/index.js index b464e2d..f855e06 100644 --- a/index.js +++ b/index.js @@ -77,12 +77,17 @@ const deploy = ({ usedocker, dockerHerokuProcessType, dockerBuildArgs, + dockerContextPath, + dockerFindRecursive, appdir, }) => { const force = !dontuseforce ? "--force" : ""; if (usedocker) { + const recursiveFlag = dockerFindRecursive ? "--recursive" : ""; + const contextPathFlag = dockerContextPath ? `--context-path ${dockerContextPath}` : ""; + execSync( - `heroku container:push ${dockerHerokuProcessType} --app ${app_name} ${dockerBuildArgs}`, + `heroku container:push ${dockerHerokuProcessType} --app ${app_name} ${dockerBuildArgs} ${recursiveFlag} ${contextPathFlag}`.trim().replace(/\s+/g, ' '), appdir ? { cwd: appdir } : null ); execSync( @@ -146,6 +151,8 @@ let heroku = { usedocker: core.getInput("usedocker") === "false" ? false : true, dockerHerokuProcessType: core.getInput("docker_heroku_process_type"), dockerBuildArgs: core.getInput("docker_build_args"), + dockerContextPath: core.getInput("docker_context_path"), + dockerFindRecursive: core.getInput("docker_find_recursive") === "false" ? false : true, appdir: core.getInput("appdir"), healthcheck: core.getInput("healthcheck"), checkstring: core.getInput("checkstring"), diff --git a/package.json b/package.json index 723346e..83ad9f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "heroku-deploy", - "version": "3.13.15", + "version": "3.13.16", "description": "A simple github action that dynamically deploys an app to heroku", "main": "index.js", "scripts": {