need4swede / Portall

Port Management Interface
MIT License
383 stars 8 forks source link

ci: Add docker image automated deploy and PR building #3

Open FoxxMD opened 3 months ago

FoxxMD commented 3 months ago

To use the github actions workflow to deploy automatically to dockerhub and github packages

All below builds are cross-platform for x86/ARM.

On Push

Triggers on these actions and publishes accordingly:

To enable

On PR

The same settings apply as above except only for dockerhub for security considerations when using pull_request_trigger so that the action does not need repo write permissions.

When a PR targeting main opened it will be built and published to dockerhub pr[issueNumber] EX pr152 and a comment with a link to the built image will be made in the PR. However this only happens if the PR has the label safe to test so you have a chance to review PR for malicious changes to github actions workflow or other things.


The docker build action is also provided a build arg APP_BUILD_VERSION that could be used by your application to display the built version based on tag or branch or pr...modify you Dockerfile with

ARG APP_BUILD_VERSION
ENV APP_VERSION=$APP_BUILD_VERSION

And then reference APP_VERSION env within your app to get the version like:

lilkidsuave commented 3 months ago

Instead of On Push, Workflow dispatch should be used to prevent accidental breakage on a stable branch. On a dev branch, On push is fine, but might break peoples image.

FoxxMD commented 3 months ago

That's reasonable but really up to the author. I have good commit discipline in my projects and don't commit to main unless im cutting a release and have never had an issue with deploying accidentally.

lilkidsuave commented 3 months ago

That's reasonable but really up to the author. I have good commit discipline in my projects and don't commit to main unless im cutting a release and have never had an issue with deploying accidentally.

And thats how I think it should be somewhat as well. But in my limited experience with docker stuff, (and lower discipline) I usually workflow dispatch to test new changes, and sometimes it breaks something and I have to revert. On push spams the workflow unless you also have the one at a time setting. Editing a Readme doesn't require a build.

Sorry for the tangent, TLDR I agree with you, I just do things a bit different (and loose).

FoxxMD commented 3 months ago

Understandable...if the author would prefer that I can remove (or they can edit) the push -> branches to remove main or add dev branches. The workflow already has workflow_dispatch so that's good to go.

Editing a Readme doesn't require a build.

True and also why the workflow includes

    paths-ignore:
      - '**.md'
      - '.github/**'

:smile: