Skip to content

Commit

Permalink
feat: add recursive heroku docker pushes
Browse files Browse the repository at this point in the history
this allows to build dedicated production images for each heroku process
type. Additionally with this change multiple images can be deployed at
once.
  • Loading branch information
Jan Zaydowicz committed Sep 25, 2021
1 parent d81c270 commit bdf88de
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,26 @@ jobs:
checkstring: "ok"
procfile: "web: gunicorn index:app"
- run: npm run test-action https://akhileshns-hd-test-4.herokuapp.com/

deploy-test-5:
runs-on: ubuntu-latest
needs: deploy-test-2
steps:
- uses: actions/checkout@v2
- run: npm run setup tests/test-3/data.json
- run: |
git config --global user.email "[email protected]"
git config --global user.name "AkhileshNS"
git add -A
git commit -m "Added data.json"
- uses: akhileshns/heroku-deploy@master
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "akhileshns-hd-test-3"
heroku_email: "[email protected]"
appdir: "tests/test-5"
usedocker: true
dockerHerokuPushRecursive: true
dockerHerokuProcessType: web
healthcheck: "https://akhileshns-hd-test-3.herokuapp.com/"
- run: npm run test-action https://akhileshns-hd-test-3.herokuapp.com/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ The action comes with additional options that you can use to configure your proj
| dontuseforce | false | Set this to true if you don't want to use --force when switching branches | true or false |
| 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_heroku_push_recursive | false | "To push one or all dedicated process type Dockerfiles e.g. `Dockerfile.web` for web. Futher usage information can be found [in the docs](https://devcenter.heroku.com/changelog-items/1191) This option only makes sense when usedocker enabled" | true or false |
| docker_build_args | false | A list of args to pass into the Docker build. This option only makes sense when usedocker enabled. | NODE_ENV |
| 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 |
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ inputs:
description: "Type of heroku process (web, worker, etc). This option only makes sense when usedocker enabled"
default: "web"
required: false
docker_heroku_push_recursive:
description: "To push one or all dedicated process type Dockerfiles e.g. `Dockerfile.web` for web. This option only makes sense when usedocker enabled"
default: "false"
required: false
docker_build_args:
description: "A list of args to pass into the Docker build. This option only makes sense when usedocker enabled"
required: false
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ const deploy = ({
usedocker,
dockerHerokuProcessType,
dockerBuildArgs,
dockerHerokuPushRecursive,
appdir,
}) => {
const force = !dontuseforce ? "--force" : "";
if (usedocker) {
const push_recursive = dockerHerokuPushRecursive ? "--recursive" : "";
execSync(
`heroku container:push ${dockerHerokuProcessType} --app ${app_name} ${dockerBuildArgs}`,
`heroku container:push ${push_recursive} ${dockerHerokuProcessType} --app ${app_name} ${dockerBuildArgs}`,
appdir ? { cwd: appdir } : null
);
execSync(
Expand Down Expand Up @@ -138,6 +140,7 @@ let heroku = {
dontautocreate: core.getInput("dontautocreate") === "false" ? false : true,
usedocker: core.getInput("usedocker") === "false" ? false : true,
dockerHerokuProcessType: core.getInput("docker_heroku_process_type"),
dockerHerokuPushRecursive: core.getInput("docker_heroku_push_recursive") === "false" ? false : true,
dockerBuildArgs: core.getInput("docker_build_args"),
appdir: core.getInput("appdir"),
healthcheck: core.getInput("healthcheck"),
Expand Down
12 changes: 12 additions & 0 deletions tests/test-5/Dockerfile.web
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.8.2-alpine3.11

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8080

CMD [ "python", "./index.py" ]
1 change: 1 addition & 0 deletions tests/test-5/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
13 changes: 13 additions & 0 deletions tests/test-5/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# IMPORTS
import os
from flask import Flask
app = Flask(__name__)
port = int(os.environ.get("PORT", 8080))

@app.route('/')
def hello_handler():
f = open("data.json");
return f.read()

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=port)
9 changes: 9 additions & 0 deletions tests/test-5/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
autopep8==1.4.4
Click==7.0
Flask==1.1.1
gunicorn==19.10.0
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
pycodestyle==2.5.0
Werkzeug==0.16.0

0 comments on commit bdf88de

Please sign in to comment.