Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support offline mode #2128

Merged
merged 7 commits into from
Jan 20, 2024
Merged

Conversation

TKaxv-7S
Copy link
Contributor

In some regions, connecting to github.com may not be as smooth.

So every time we using uses: method, it is not a good way to fetch and pull the current action content, and I think the action tag will also be rarely updated.

We can add a configurable option in OfflineMode to control it, setting the default value to false, so this will not affect other users.

PS: This feature is mainly intended for use by Gitea act_runner. If possible, I will also create a pull request over there.

@TKaxv-7S TKaxv-7S requested a review from a team as a code owner December 16, 2023 04:49
@wolfogre
Copy link
Member

Can you provide a detailed explanation of how offline mode works with act runner?

BTW, if you cannot access github.com, you can handle it with use: https://custom_domain/some/actions, like https://gitea.com/actions/checkout, it's supported by act runner.

@ChristopherHX
Copy link
Contributor

ChristopherHX commented Dec 20, 2023

In nektos act is forcepull enabled by default, I would expect that offline mode would also stop pulling existing images e.g. turning the default force-pull off.

As far as I understand, this change relies on the cache of act and skip all updates to cached actions. Due to that git.fetch can not return any errors anymore while cannot connect to github.

I assume not cached actions will be cloned once per tag and then never updated.

In act_runner forcepull is still off by default, however I don't know why it is still disabled there. It's the same as with force-rebuild beeing still disabled in act_runner. Those features beeing turned off caused bugs for users expecting uptodate images or docker actions

@ChristopherHX
Copy link
Contributor

My plans to create a new ActionCache for nektos/act was rejected silently by all members of nektos/act, by not commenting at all

That would also have an easy offline mode, even with remote action overrides to a local folder of your choice.

@TKaxv-7S
Copy link
Contributor Author

Can you provide a detailed explanation of how offline mode works with act runner?

BTW, if you cannot access github.com, you can handle it with use: https://custom_domain/some/actions, like https://gitea.com/actions/checkout, it's supported by act runner.

Yes, I created a new pull request at act_runner#454
This code is very limited.

@TKaxv-7S
Copy link
Contributor Author

My plans to create a new ActionCache for nektos/act was rejected silently by all members of nektos/act, by not commenting at all

That would also have an easy offline mode, even with remote action overrides to a local folder of your choice.

I'm sorry for your experience. I only added very few features, and you did more, but I don't have the ability to help you :(

@ChristopherHX
Copy link
Contributor

ChristopherHX commented Jan 8, 2024

No progress here? You would need two approvals for getting this merged.

FYI My approval for this depends on the following

In nektos act is forcepull enabled by default, I would expect that offline mode would also stop pulling existing images e.g. turning the default force-pull off.

Alternatively I think it might be reasonable that everywhere the forcepull is checked a extra check to OfflineMode is done to behave like forcepull is disabled if OfflineMode is active.

e.g.

if forcepull {
}
if !forcepull {
}

becomes

if !OfflineMode && forcepull {
}
if OfflineMode || !forcepull {
}

I'm not requesting changes in the hard way, so that two other maintainer can still vote to get this merged as it is

I couldn't find the related issue about running act offline, but I believe it exists

@TKaxv-7S
Copy link
Contributor Author

TKaxv-7S commented Jan 9, 2024

No progress here? You would need two approvals for getting this merged.

FYI My approval for this depends on the following

In nektos act is forcepull enabled by default, I would expect that offline mode would also stop pulling existing images e.g. turning the default force-pull off.

Alternatively I think it might be reasonable that everywhere the forcepull is checked a extra check to OfflineMode is done to behave like forcepull is disabled if OfflineMode is active.

e.g.

if forcepull {
}
if !forcepull {
}

becomes

if !OfflineMode && forcepull {
}
if OfflineMode || !forcepull {
}

I'm not requesting changes in the hard way, so that two other maintainer can still vote to get this merged as it is

I couldn't find the related issue about running act offline, but I believe it exists

I agree with this suggestion. I have modified the code and committed it here

Copy link
Contributor

@ChristopherHX ChristopherHX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you understood the opposite of what I actually meant.

You are also seem to missing a line here:

rootCmd.Flags().BoolVarP(&input.forcePull, "pull", "p", true, "pull docker image(s) even if already present")
for your cli flag

So what you seem to have changed makes the following
act --offline-mode (act --offline-mode --pull=true) ignore offline mode. (forcepull has default value true in act)

A user of act would have to write
act --offline-mode --pull=false to get the offline mode.

What I meant is
act --offline-mode (act --offline-mode --pull=true) turns on offline mode and turns off force pull.

@@ -66,7 +66,7 @@ func cloneIfRequired(rc *RunContext, remoteReusableWorkflow remoteReusableWorkfl
Ref: remoteReusableWorkflow.Ref,
Dir: targetDirectory,
Token: rc.Config.Token,
OfflineMode: rc.Config.ActionOfflineMode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually meant to keep this, like it was before

@@ -67,7 +67,7 @@ func (sar *stepActionRemote) prepareActionExecutor() common.Executor {
Ref: sar.remoteAction.Ref,
Dir: actionDir,
Token: github.Token,
OfflineMode: sar.RunContext.Config.ActionOfflineMode,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually meant to keep this, like it was before

@ChristopherHX
Copy link
Contributor

The lines I meant would be

So that the offline mode can turn off forcepull.

@TKaxv-7S
Copy link
Contributor Author

TKaxv-7S commented Jan 9, 2024

@ChristopherHX Sorry for misunderstanding your meaning earlier. Now I have modified the code and committed it here.

Copy link
Contributor

@ChristopherHX ChristopherHX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works perfectly fine for me on windows, thank you.

Can rerun act with offlinemode using it's cache without getting any error due to turning off internet.

.\t\.github\workflows\t.yaml

on: push
jobs:
  _:
    runs-on: t
    steps:
    - uses: actions/download-artifact@v4 # This actions obviously fails, but never due to no internet

via cli

.\act.exe -C .\t\ -P t=-self-hosted --action-offline-mode

Once the mode is enabled the following is the new behavior

  • not yet cloned actions will be cloned in this mode, assumes internet is working
  • already cloned actions won't be updated (breaks updates of rolling tags / branches, but that's a user decision)
  • already pulled images won't be updated
  • works offline, with disabled internet
    • no rewriting of workflow files needed

One pending review, from maintainers, required...

Copy link

codecov bot commented Jan 9, 2024

Codecov Report

Attention: 1019 lines in your changes are missing coverage. Please review.

Comparison is base (4989f44) 61.22% compared to head (da0191e) 60.78%.
Report is 299 commits behind head on master.

Files Patch % Lines
pkg/artifactcache/handler.go 65.46% 102 Missing and 42 partials ⚠️
pkg/runner/run_context.go 73.37% 75 Missing and 19 partials ⚠️
pkg/runner/expression.go 55.17% 66 Missing and 12 partials ⚠️
pkg/runner/action_cache.go 50.74% 49 Missing and 17 partials ⚠️
pkg/container/docker_run.go 1.51% 64 Missing and 1 partial ⚠️
pkg/container/docker_network.go 0.00% 56 Missing ⚠️
pkg/model/planner.go 28.57% 53 Missing and 2 partials ⚠️
pkg/runner/reusable_workflow.go 52.47% 42 Missing and 6 partials ⚠️
pkg/model/workflow.go 43.37% 40 Missing and 7 partials ⚠️
pkg/common/outbound_ip.go 0.00% 44 Missing ⚠️
... and 27 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2128      +/-   ##
==========================================
- Coverage   61.22%   60.78%   -0.44%     
==========================================
  Files          46       53       +7     
  Lines        7141     8966    +1825     
==========================================
+ Hits         4372     5450    +1078     
- Misses       2462     3079     +617     
- Partials      307      437     +130     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TKaxv-7S
Copy link
Contributor Author

TKaxv-7S commented Jan 9, 2024

Works perfectly fine for me on windows, thank you.

Can rerun act with offlinemode using it's cache without getting any error due to turning off internet.

.\t\.github\workflows\t.yaml

on: push
jobs:
  _:
    runs-on: t
    steps:
    - uses: actions/download-artifact@v4 # This actions obviously fails, but never due to no internet

via cli

.\act.exe -C .\t\ -P t=-self-hosted --action-offline-mode

Once the mode is enabled the following is the new behavior

  • not yet cloned actions will be cloned in this mode, assumes internet is working

  • already cloned actions won't be updated (breaks updates of rolling tags / branches, but that's a user decision)

  • already pulled images won't be updated

  • works offline, with disabled internet

    • no rewriting of workflow files needed

One pending review, from maintainers, required...

Thank you for your detailed description of this feature, which makes the originally vague function clearer and easier to understand

@mergify mergify bot merged commit f055d4a into nektos:master Jan 20, 2024
10 checks passed
jmikedupont2 pushed a commit to meta-introspector/act that referenced this pull request Mar 10, 2024
* Add: Actions Offline Mode

* Add: Actions Offline Mode

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants