1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-30 19:22:09 +00:00
Commit graph

20 commits

Author SHA1 Message Date
Earl Warren
c7e2db2559
chore: cache: handler: test coverage for fatal errors 2025-09-05 17:30:08 +02:00
Earl Warren
6c4e705f97
chore: cache: split caches implementation out of handler
- create the caches interface and matching cachesImpl
- move the cache logic out of handler
  - openDB
  - readCache
  - useCache
  - gcCache
  - access to the storage struct
    - serve
    - commit
    - exist
    - write
- add getCaches / setCaches to the handler interface so it can be
  used by tests. The caches test should be implemented independently
  in the future but this is a different kind of cleanup.
- no functional change, minimal refactor
2025-09-05 17:30:08 +02:00
Earl Warren
37f634fd31
fix: cache: call fatal() on errors that are not recoverable
- responseFatalJSON(w, r, err) replaces responseJSON(w, r, 500, err)
  and calls fatal() when the following fail because they are
  not recoverable. There may be other non-recoverable errors but
  it is difficult to be 100% sure they cannot be engineered by the
  caller of the API for DoS purposes.
  - openDB
  - findCache
  - cache.Repo != repo
- wrap errors in
  - openDB() - it was missing
  - readCache() - it was missing
  - useCache() - it was missing
  - findCache() - some had identical messages
- in gc
  - replace logger.Warnf with h.fatal
  - differentiate errors that have identical messages
  - call fatal if openDB fails instead of returning
2025-09-05 17:29:04 +02:00
Earl Warren
36ca627f2e
feat: cache: fatal() helper to gracefully terminate the runner
in case of an error that is not recoverable (e.g. failing to open the
bolthold database), the cache can call fatal() to log the error and
send a TERM signal that will gracefully shutdown the daemon.
2025-09-05 17:26:12 +02:00
Earl Warren
39dd708768
chore: cosmetic fixes 2025-09-05 13:22:59 +02:00
Mathieu Fenniak
a3aedba3f1
refactor: remove duplicate computeMac function (#936)
It was raised during embargo review of #925 that there are two implementations of `computeMac`; this PR fixes that.

As all the tests for `computeMac` were in the `artifactcache` package, it made more sense to keep the method there.  That required reversing the dependency `artifactcache->cacheproxy` package dependency -- it makes more sense to me for the proxy to depend on the cache, rather than vice-versa.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/936): <!--number 936 --><!--line 0 --><!--description cmVmYWN0b3I6IHJlbW92ZSBkdXBsaWNhdGUgY29tcHV0ZU1hYyBmdW5jdGlvbg==-->refactor: remove duplicate computeMac function<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/936
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
2025-09-05 06:01:49 +00:00
Earl Warren
69c6c70845
chore: refactor act/artifactcache Handler to an interface (#934)
- the Handler struct becomes handler (lowercase)
- the Handler interface is defined to be the existing methods
- isClosed() is added and used only in tests
- setgcAt() is added and used only in tests

---

This is to allow mocking the Handler interface for testing.

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/934): <!--number 934 --><!--line 0 --><!--description Y2hvcmU6IHJlZmFjdG9yIGFjdC9hcnRpZmFjdGNhY2hlIEhhbmRsZXIgdG8gYW4gaW50ZXJmYWNl-->chore: refactor act/artifactcache Handler to an interface<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/934
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-09-04 14:38:50 +00:00
Mathieu Fenniak
4bd93294d4
add WriteIsolationKey to MAC 2025-09-01 13:45:43 +02:00
Mathieu Fenniak
6c35ea4fd9
add unit tests for all changes in artifactcache 2025-09-01 13:45:43 +02:00
Earl Warren
c377159121 chore: use the same .golangci.yml as the runner & gofumpt over gofmt (#206)
To prepare for a smooth merge in the runner codebase.

- run with --fix for gofumpt and golangci
- manual edits for
  - disabling useless package naming warning
  - rename variables that had underscore in their name
  - remove trailing else at the end of a few functions

Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/206
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-28 12:26:41 +00:00
Earl Warren
1b0c31121a chore(tests): add coverage for ./pkg/artifactcache (#198)
https://code.forgejo.org/forgejo/act/actions/runs/1157/jobs/0#jobstep-10-251
Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/198
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
2025-07-27 15:25:14 +00:00
Christoph Heiss
92b7df3da7 fix: artifacts: format IP:port pair using net.JoinHostPort()
This ensures that brackets are added for IPv6 addresses.
Without this, This could result in addresses like "2001:db8::1:3456",
which - obviously - would break further down and prevent the server from
starting.

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
2025-06-01 12:10:47 +02:00
Kwonunn
ef94958cd5 review: Gusted review 2025-03-21 13:45:51 +00:00
Kwonunn
62310a5a09 set external url header 2025-03-21 13:45:51 +00:00
Kwonunn
e54faaf56d fix tests for cache proxy 2025-03-21 13:45:51 +00:00
Michael Kriese
1082b31367 fix: partial secure cache 2025-03-21 13:45:51 +00:00
ChristopherHX
017db5edae fix: cache adjust restore order of exact key matches (#2267)
* wip: adjust restore order

* fixup

* add tests

* cleanup

* fix typo

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 88ac88c5413a430b41d767a942c8e70e778e1d61)
2024-11-07 16:25:40 +01:00
Jason Song
b0c54edc78 Support overwriting caches (#2265)
* feat: support overwrite caches

* test: fix case

* test: fix get_with_multiple_keys

* chore: use atomic.Bool

* test: improve get_with_multiple_keys

* chore: use ping to improve path

* fix: wrong CompareAndSwap

* test: TestHandler_gcCache

* chore: lint code

* chore: lint code

(cherry picked from commit 087b28afc56351b93dd68d7e59a2c8740f6c0e44)
2024-11-07 16:25:26 +01:00
ChristopherHX
4d3a674f12 refactor: open boltdb only while using it (#1879)
* refactor: open boltdb only while using it

* patch

* Update handler_test.go

* Update handler_test.go

* Update handler_test.go

* Update handler.go

* timeout * 10

* pr feedback

* fixup
2023-07-10 16:57:06 +00:00
Jason Song
b51f608660 Support cache (#1770)
* feat: port

* fix: use httprouter

* fix: WriteHeader

* fix: bolthold

* fix: bugs

* chore: one less file

* test: test handler

* fix: bug in id

* test: fix cases

* chore: tidy

* fix: use atomic.Int32

* fix: use atomic.Store

* feat: support close

* chore: lint

* fix: cache keys are case insensitive

* fix: options

* fix: use options

* fix: close

* fix: ignore close error

* Revert "fix: close"

This reverts commit d53ea7568ba03908eb153031c435008fd47e7ccb.

* fix: cacheUrlKey

* fix: nil close

* chore: lint code

* fix: test key

* test: case insensitive

* chore: lint
2023-04-28 15:57:40 +00:00