Fix container network issue #56

Merged
wolfogre merged 18 commits from sillyguodong/act:feature/network into main 2023-05-16 06:03:55 +00:00
Member

Follow: gitea/act_runner#184
Close gitea/act_runner#177

changes:

  • act create new networks only if the value of ContainerNetworkMode which is passed by act_runner is empty string, and remove these networks at last.
  • In the docker create phase, specify the network to which containers will connect. Because, if not specify , container will connect to bridge network which is created automatically by Docker.
    • If the network is user defined network ( the value of container.network is empty or <custom-network>. Because, the network created by act is also user defined network.), will also specify alias by --network-alias. The alias of service is <service-id>. So we can be access service container by <service-id>:<port> in the steps of job.
  • Won't try to docker network connect network after docker start any more.
    • Because on the one hand, docker network connect applies only to user defined networks, if try to docker network connect host <container-name> will return error.
    • On the other hand, we just specify network in the stage of docker create, the same effect can be achieved.
  • Won't try to remove containers and networks berfore the stage of docker start, because the name of these containers and netwoks won't be repeat.
Follow: https://gitea.com/gitea/act_runner/pulls/184 Close https://gitea.com/gitea/act_runner/issues/177 #### changes: - `act` create new networks only if the value of `ContainerNetworkMode` which is passed by `act_runner` is empty string, and remove these networks at last. - In the `docker create` phase, specify the network to which containers will connect. Because, if not specify , container will connect to `bridge` network which is created automatically by Docker. - If the network is user defined network ( the value of `container.network` is empty or `<custom-network>`. Because, the network created by `act` is also user defined network.), will also specify alias by `--network-alias`. The alias of service is `<service-id>`. So we can be access service container by `<service-id>:<port>` in the steps of job. - Won't try to `docker network connect ` network after `docker start` any more. - Because on the one hand, `docker network connect` applies only to user defined networks, if try to `docker network connect host <container-name>` will return error. - On the other hand, we just specify network in the stage of `docker create`, the same effect can be achieved. - Won't try to remove containers and networks berfore the stage of `docker start`, because the name of these containers and netwoks won't be repeat.
sillyguodong added 1 commit 2023-05-11 07:46:08 +00:00
fix container network issue
All checks were successful
checks / check and test (pull_request) Successful in 47s
3ed821aaa4
sillyguodong added 1 commit 2023-05-11 07:49:25 +00:00
fix comment
All checks were successful
checks / check and test (pull_request) Successful in 27s
a4fe1971c6
sillyguodong added 1 commit 2023-05-11 08:37:13 +00:00
add --network-alias only user defined network
All checks were successful
checks / check and test (pull_request) Successful in 28s
10152225f3
sillyguodong added 1 commit 2023-05-11 09:16:37 +00:00
fix close service containers
All checks were successful
checks / check and test (pull_request) Successful in 30s
0b4a948958
sillyguodong added 1 commit 2023-05-11 09:20:21 +00:00
fix
All checks were successful
checks / check and test (pull_request) Successful in 29s
997cb0f7e9
sillyguodong added 1 commit 2023-05-11 09:29:10 +00:00
do not disconnect if host network
All checks were successful
checks / check and test (pull_request) Successful in 28s
c90b03fa81
sillyguodong added 1 commit 2023-05-11 10:10:22 +00:00
disconnect comment
All checks were successful
checks / check and test (pull_request) Successful in 28s
13e45e3235
ligang added a new dependency 2023-05-11 11:22:23 +00:00
ligang removed a dependency 2023-05-11 11:23:38 +00:00
sillyguodong changed title from WIP: Fix container network issue to Fix container network issue 2023-05-12 04:21:50 +00:00
sillyguodong added 1 commit 2023-05-12 05:16:18 +00:00
comment
All checks were successful
checks / check and test (pull_request) Successful in 30s
0a17b56f31
wolfogre reviewed 2023-05-12 07:37:35 +00:00
@ -77,6 +78,27 @@ func (c Config) GetToken() string {
return token
}
func (c Config) IsNetworkModeHost() bool {
Owner

Maybe we could reuse container.NetworkMode

Maybe we could reuse `container.NetworkMode`
sillyguodong marked this conversation as resolved
sillyguodong added 1 commit 2023-05-12 08:25:52 +00:00
reuse NetworkType in docker package
All checks were successful
checks / check and test (pull_request) Successful in 28s
5b6cfbd396
wolfogre reviewed 2023-05-12 08:58:25 +00:00
@ -265,0 +267,4 @@
networkName = fmt.Sprintf("%s-network", rc.jobContainerName())
} else {
networkName = string(*rc.Config.ContainerNetworkMode)
}
Owner

Maybe

		networkName := rc.Config.ContainerNetworkMode
		if networkName.IsBridge() {
        	// TODO explain why
			networkName = container.NetworkMode(fmt.Sprintf("%s-network", rc.jobContainerName()))
		}
Maybe ```go networkName := rc.Config.ContainerNetworkMode if networkName.IsBridge() { // TODO explain why networkName = container.NetworkMode(fmt.Sprintf("%s-network", rc.jobContainerName())) } ```
sillyguodong marked this conversation as resolved
@ -69,0 +62,4 @@
EventJSON string // the content of JSON file to use for event.json in containers, overrides EventPath
ContainerNamePrefix string // the prefix of container name
ContainerMaxLifetime time.Duration // the max lifetime of job containers
ContainerNetworkMode *docker_container.NetworkMode // the network mode of job containers
Owner

Why not docker_container.NetworkMode instead of *docker_container.NetworkMode

Why not `docker_container.NetworkMode` instead of `*docker_container.NetworkMode`
sillyguodong marked this conversation as resolved
sillyguodong added 1 commit 2023-05-13 01:01:26 +00:00
refactor
All checks were successful
checks / check and test (pull_request) Successful in 28s
d378c57960
sillyguodong added 1 commit 2023-05-13 01:05:47 +00:00
delete unuse func param
All checks were successful
checks / check and test (pull_request) Successful in 28s
d680c00163
sillyguodong added 1 commit 2023-05-13 01:06:30 +00:00
fix typo
All checks were successful
checks / check and test (pull_request) Successful in 27s
07d77ed2ee
sillyguodong added 1 commit 2023-05-13 01:09:32 +00:00
fix
All checks were successful
checks / check and test (pull_request) Successful in 30s
f625bb5f18
sillyguodong added 1 commit 2023-05-15 04:18:32 +00:00
add comment
All checks were successful
checks / check and test (pull_request) Successful in 29s
17529d018d
sillyguodong added 1 commit 2023-05-15 06:57:35 +00:00
delete blank line
All checks were successful
checks / check and test (pull_request) Successful in 29s
02cc5068a3
sillyguodong requested review from wolfogre 2023-05-15 06:58:06 +00:00
sillyguodong added 1 commit 2023-05-16 05:46:25 +00:00
delete needCreateNetwork
All checks were successful
checks / check and test (pull_request) Successful in 29s
45f5bb7b88
wolfogre approved these changes 2023-05-16 05:50:40 +00:00
sillyguodong added 1 commit 2023-05-16 05:51:53 +00:00
fix comment
All checks were successful
checks / check and test (pull_request) Successful in 28s
617f50eebf
wolfogre added 1 commit 2023-05-16 06:03:08 +00:00
Merge branch 'main' into feature/network
All checks were successful
checks / check and test (pull_request) Successful in 30s
bffce321b3
wolfogre merged commit 9283cfc9b1 into main 2023-05-16 06:03:55 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: gitea/act#56
No description provided.