Skip to content

[ONE-Dockerizing] Scripts that can run onecc using docker containers#9737

Closed
holawan wants to merge 9 commits intoSamsung:masterfrom
holawan:onecc-docker
Closed

[ONE-Dockerizing] Scripts that can run onecc using docker containers#9737
holawan wants to merge 9 commits intoSamsung:masterfrom
holawan:onecc-docker

Conversation

@holawan
Copy link
Member

@holawan holawan commented Sep 19, 2022

1st PR

This PR is a script that builds images and drives containers to run onecc with docker containers

ONE-DCO-1.0.-Signed-off-by: Dongwan Kim asdf134652@gmail.com

2nd PR

This PR is an improved script to reflect the review

  • How to get version
  • Functionalize duplicate use options
  • Check Dockerfile Existence
  • Run docker container

3rd PR

This PR has added error handling logic

4th PR

This PR was created to add README to "onecc-docker".

5th PR

This PR has added an API request excess exception handling code

parent issue: #9712 #9721
draft: #9722

/cc @Samsung/ootpg

This PR is a script that builds images and drives containers to run onecc with docker containers
ONE-DCO-1.0.-Signed-off-by: Dongwan Kim <asdf134652@gmail.com>
@holawan holawan added the SSAFY label Sep 19, 2022
@holawan holawan requested a review from jyoungyun September 19, 2022 08:11
@holawan holawan changed the title [ONE-Dockerizing] Scripts that can run onec using docker containers [ONE-Dockerizing] Scripts that can run onecc using docker containers Sep 19, 2022
@seanshpark

This comment was marked as resolved.

@mhs4670go

This comment was marked as resolved.

@mhs4670go

This comment was marked as resolved.

user_cmd = ''.join(sys.argv[1:])
run_cmd = ["docker", "run", "--rm", "--name", contianer_name, "-v", "${HOME}:${HOME}", "-e", "HOME=${HOME}", "-w", work_dir, image_name, user_cmd]
cmd = ' '.join(run_cmd)
subprocess.run(cmd,shell=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

In this onecc-docker, there are three method call when the subprocess is invoked - subprocess.run, subprocess.call, Popen. Is there a reason to use three different functions?

How about make a method that runs a command?

def run_subprocess(cmd):
    ret = subprocess.run(cmd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # do something or return the results
    # error handling might be needed

@holawan

This comment was marked as resolved.

@mhs4670go

This comment was marked as resolved.

@holawan
Copy link
Member Author

holawan commented Sep 19, 2022

@mhs4670go , @jyoungyun
There seems to be a lot of corrections in our code.
May I continue to talk in this PR and improve the code?

@mhs4670go
Copy link
Collaborator

May I continue to talk in this PR and improve the code?

Yes. Splitting the PR will split the information, which makes it difficult to find the history later.

import os
import requests


Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add usage for this script? The argparse library will help you to write user friendly interfaces.

Copy link
Contributor

@morumoru morumoru Sep 20, 2022

Choose a reason for hiding this comment

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

You mean that make -h option on onecc-docker with argparse library?
I think that -h option is duplicated with onecc's -h option.
Should we make new flag for getting onecc's arguments?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think onecc-docker can take own argument. For example, if the user want to pass a personal access token to the request headers, onecc-docker should take a token value from argument. In view of this case, this script should implement a separate argparser.

Copy link
Contributor

Choose a reason for hiding this comment

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

If onecc is already installed when running onecc-docker, shows onecc help message and if onecc is not installed, shows onecc-docker help message. What about this solution?

First of all, let's put the PR without considering -h option handling.

Copy link
Member Author

Choose a reason for hiding this comment

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

If onecc is already installed when running onecc-docker, shows onecc help message and if onecc is not installed, shows onecc-docker help message. What about this solution?

Yes, after finalizing existing developments, it would be a good idea to consider them!

First of all, let's put the PR without considering -h option handling.

Okay.




def main():
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, I can't use the github rest api without authorization due to in-house network issue. So I suggest to support request header so that the users who need it can use it.

headers["Authorization"] = "token {}".format(/*token*/)
response = requests.get("https://api.github.com/repos/Samsung/ONE/tags", headers=headers)

https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting
https://docs.github.com/en/rest/overview/resources-in-the-rest-api#oauth2-token-sent-in-a-header

@jyoungyun
Copy link
Contributor

I think compiler/one-docker folder python files isn't checked with format checker.

I made #9742 PR.

@holawan Could you rebase this PR after merging #9742 PR. :)

@holawan holawan marked this pull request as draft September 20, 2022 01:39
@holawan holawan added PR/NO MERGE Please don't merge. I'm still working on this :) DRAFT A draft issue or PR for sharing one's current working status and discussion. labels Sep 20, 2022
This PR has added error handling logic

ONE-DCO-1.0.-Signed-off-by: Dongwan Kim <asdf134652@gmail.com>
This PR was created to add README to "onecc-docker".

ONE-DCO-1.0.-Signed-off-by: Dongwan Kim <asdf134652@gmail.com>
Comment on lines 61 to 66
build_cmd = [
"docker", "build", "-t", image_name, "--build-arg", build_arg, script_path
]
print('build Docker image ...')
_run(build_cmd)
print('Dockerfile successfully built.')
Copy link
Member Author

Choose a reason for hiding this comment

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

@jyoungyun , when the user does not have a docker image, the build time takes about 10 minutes. Is it necessary to print out the flow of the docker being built?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think it is necessary.

This PR has added an API request excess exception handling code

ONE-DCO-1.0.-Signed-off-by: Dongwan Kim <asdf134652@gmail.com>
@@ -0,0 +1,263 @@
# onecc-docker

`onecc-docker` supports `one-cmd`, which is currently only supported by ubuntu 18.04, in more OS.
Copy link
Collaborator

@mhs4670go mhs4670go Sep 20, 2022

Choose a reason for hiding this comment

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

`onecc-docker` -> _onecc-docker_

Suggested change
`onecc-docker` supports `one-cmd`, which is currently only supported by ubuntu 18.04, in more OS.
_onecc-docker_ supports `one-cmds`, which is currently only supported on ubuntu 18.04, in more OS.

Copy link
Contributor

Choose a reason for hiding this comment

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

Q) what is in more OS. ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Q) what is in more OS. ?

More OSs can provide it.

Copy link
Contributor

Choose a reason for hiding this comment

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

only supported on ... in more OS.

I cann't catch the meaning of this sentense. can you elaborate a bit?

Copy link
Member Author

Choose a reason for hiding this comment

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

This means that onecc-docker supports running onecc in environments other than ubuntu:18.04.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about

  • onecc-docker can expand one-cmds in more platforms than just Ubuntu 18.04/20.04.
  • or
  • We can use one-cmds in more platorms than just Ubuntu 18.04/20.04 through onecc-docker.

import json
import os
import requests
import argparse
Copy link
Collaborator

Choose a reason for hiding this comment

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

This argparse has been added for https://github.com/Samsung/ONE/pull/9737/files#r974949214. Is it going to be used?

Copy link
Member Author

Choose a reason for hiding this comment

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

We haven't started the task on "argparse" yet.
I am trying to use it according to @jyoungyun's opinion.
I think I can give you a detailed answer after the meeting tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add token argument for in-house developers?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes let's try that.

import os
import requests


Copy link
Contributor

Choose a reason for hiding this comment

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

If onecc is already installed when running onecc-docker, shows onecc help message and if onecc is not installed, shows onecc-docker help message. What about this solution?

First of all, let's put the PR without considering -h option handling.

import json
import os
import requests
import argparse
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add token argument for in-house developers?

Comment on lines 61 to 66
build_cmd = [
"docker", "build", "-t", image_name, "--build-arg", build_arg, script_path
]
print('build Docker image ...')
_run(build_cmd)
print('Dockerfile successfully built.')
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think it is necessary.

response = requests.get(TAG_URL)
response.raise_for_status()
except requests.exceptions.RequestException as e:
raise SystemExit(e)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you user-friendly print an error message?

SystemExit('blah blah blah')

Copy link
Contributor

@morumoru morumoru Sep 22, 2022

Choose a reason for hiding this comment

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

When error occured in requests for example "401 Client Error: Unauthorized for url: https://api.github.com/repos/Samsung/ONE/releases/latest" message is printed to bash (Git api sent this message from server)

Should I print more information except this?

@jyoungyun

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. I think the message is not friendly to the users. :)
You can see some error messages in https://github.com/Samsung/ONE/blob/master/compiler/one-cmds/utils.py file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for advice! I'll check utils.py.




## Examples
Copy link
Contributor

Choose a reason for hiding this comment

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

What about separating this content into a separate file like tutorial.md?

@holawan
Copy link
Member Author

holawan commented Sep 21, 2022

@jyoungyun , we will proceed with code refactoring by collecting your opinions. If our code has been fixed and you think it's okay to merge, can you please tell me?

## Description

For now, `one-cmds` tools only support Ubuntu 18.04 and 20.04(not officially).
So people in other environments can't use our tools unless they upgrade the OS (or install Ubuntu OS).
Copy link
Contributor

Choose a reason for hiding this comment

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

they upgrade the OS

Actually, users may use recent Ubutuntu 22.04. Thus it is likely they downgrade the OS

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, users may use recent Ubutuntu 22.04. Thus it is likely they downgrade the OS

How about changing it like this?

Therefore, it is difficult for people in different environments to use our tools without using ubuntu18:04.

### Check Docker Image Presence and Build Image

- To prevent repetitive image generation, we verify that there is an `onecc` image of the latest `one` release version.
- If not, build the docker image using the docker file.
Copy link
Contributor

Choose a reason for hiding this comment

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

build -> rebuild ?

Copy link
Member Author

Choose a reason for hiding this comment

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

In my opinion, we build the docker image only once (unless the user intentionally deletes the image), what we repeat is considered to be the creation and deletion of the container.
@jyoungyun
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

build -> rebuild ?

@seanshpark I can't catch your intention. :( Could you explain more?
The docker image is built only once there is no image with the same name. So I think build is more suitable for this step...

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, this maybe because I'm not a good Docker user/developer.
What I see is a Docker image. from the explanation, when the latest is changed, it sounds like Docker image is built again. So from the though of again, it looks like rebuild.
Technically it looks like build not rebuild so, we can go with build

0 directories, 6 files
```

#### `-h` ,`--help`
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe still WIP?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean help message only for onecc-docker? This is under discussion with @jyoungyun .

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's discuss after the code supporting the input arguments is shared. :)

@jyoungyun
Copy link
Contributor

@holawan

we will proceed with code refactoring by collecting your opinions. If our code has been fixed and you think it's okay to merge, can you please tell me?

Of course. If there is nothing more to modify, I will let you know. :)

holawan and others added 2 commits September 22, 2022 17:39
This PR has added README fixes and Tutorial

ONE-DCO-1.0.-Signed-off-by: Dongwan Kim <asdf134652@gmail.com>
This PR has added argmentParser to onecc-docker

ONE-DCO-1.0.-Signed-off-by: Junsu Kim <xofkdqkqh@naver.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DRAFT A draft issue or PR for sharing one's current working status and discussion. PR/NO MERGE Please don't merge. I'm still working on this :) SSAFY

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants