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

chore: run container script run through CLI args #6690

Merged
merged 1 commit into from
Dec 23, 2019

Conversation

codedsun
Copy link
Contributor

Fixes #6598

Short description of what this resolves:

Container script now can be run by CLI args instead of envt variables

Checklist

  • I have read the Contribution & Best practices Guide and my PR follows them.
  • My branch is up-to-date with the Upstream development branch.
  • The unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • All the functions created/modified in this PR contain relevant docstrings.

@codecov
Copy link

codecov bot commented Dec 22, 2019

Codecov Report

Merging #6690 into development will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #6690      +/-   ##
===============================================
- Coverage        65.44%   65.43%   -0.01%     
===============================================
  Files              300      300              
  Lines            15299    15299              
===============================================
- Hits             10012    10011       -1     
- Misses            5287     5288       +1
Impacted Files Coverage Δ
app/models/event.py 78.57% <0%> (-0.36%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a71e47...6c3e7a3. Read the comment docs.

@codedsun
Copy link
Contributor Author

@iamareebjamal Please review.

C_FORCE_ROOT: "true"
command: run celery
Copy link
Member

Choose a reason for hiding this comment

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

Let's just use celery, instead of run celery

Copy link
Member

Choose a reason for hiding this comment

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

And api should start when no argument is passed and also when api argument is passed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok doing the change.

@codedsun
Copy link
Contributor Author

codedsun commented Dec 23, 2019

@iamareebjamal Check now, done the changes! Also we have to pass this command in DockerFile while starting script, correct?

Dockerfile Outdated
@@ -26,4 +26,4 @@ WORKDIR /data/app
ADD . .

EXPOSE 8080
CMD ["sh", "scripts/container_start.sh"]
CMD ["sh", "scripts/container_start.sh run "]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iamareebjamal How do we pass the command from celery container here?

Copy link
Member

Choose a reason for hiding this comment

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

Change this to ENTRYPOINT

echo "[LOG] Using database: ${DATABASE_URL}"
echo "[LOG] Using redis: ${REDIS_URL}"

if [ "$2" = "" ] || [ "$2" = "api" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

See how default parameters are handled above


if [ "$DEPLOYMENT" == "api" ]
if
[ "$1" = "run" ]
Copy link
Member

Choose a reason for hiding this comment

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

Remove as told. No need for run

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@@ -1,12 +1,11 @@
#!/bin/sh
export DEPLOYMENT=${DEPLOYMENT:-api}
DEPLOYMENT=${1:-api}
Copy link
Member

Choose a reason for hiding this comment

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

Why removed export?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why we want it to be global?

Copy link
Member

Choose a reason for hiding this comment

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

So that we can know inside the container which one it is


echo "[LOG] Deploying ${DEPLOYMENT}"
echo "[LOG] Using database: ${DATABASE_URL}"
echo "[LOG] Using redis: ${REDIS_URL}"

if [ "$DEPLOYMENT" == "api" ]
then
if [ "$DEPLOYMENT" = "api" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

revert

if [ "$DEPLOYMENT" == "celery" ]
then

if [ "$DEPLOYMENT" = "celery" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

revert

@iamareebjamal
Copy link
Member

Tested?

@codedsun codedsun force-pushed the container-2 branch 2 times, most recently from ae17595 to bbf3e93 Compare December 23, 2019 15:32
@codedsun
Copy link
Contributor Author

codedsun commented Dec 23, 2019

Not working for celery while running docker-compose up

@codedsun
Copy link
Contributor Author

codedsun commented Dec 23, 2019

@iamareebjamal the docker-compose is directly running celery instead of using it in entrypoint

Log

opev-web    | [LOG] Using redis: redis://redis:6379/0
opev-web    | [LOG] Waiting for Database
opev-web    | [LOG] Database Up
opev-web    | [LOG] Preparing database
opev-celery | usage: celery <command> [options] 
opev-celery | 
opev-celery | Show help screen and exit.
opev-celery | 
opev-celery | positional arguments:
opev-celery |   args
opev-celery | 
opev-celery | optional arguments:
opev-celery |   -h, --help       

@codedsun
Copy link
Contributor Author

@iamareebjamal Ref: https://stackoverflow.com/a/40843513/6026355

it says so, where I am wrong

@iamareebjamal
Copy link
Member

Are you building the image or just using the eventyay image

@codedsun
Copy link
Contributor Author

codedsun commented Dec 23, 2019

Are you building the image or just using the eventyay image

I am not sure about this, how to know?. I only ran docker-compose up

@codedsun
Copy link
Contributor Author

shit I was using the eventyay image

@iamareebjamal
Copy link
Member

Then you're not building the image, and obviously it won't work. Remove image: tag in docker compose file in default section and replace it with build: .

Locally, don't commit and push

@codedsun
Copy link
Contributor Author

@iamareebjamal still getting errors

Successfully tagged open-event-server_celery:latest
WARNING: Image for service celery was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating opev-postgres ... done
Creating opev-redis    ... done
Creating opev-celery   ... error
Creating opev-web      ... 

Creating opev-web      ... error

ERROR: for opev-web  Cannot start service web: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"scripts/container_start.sh\": permission denied": unknown

ERROR: for celery  Cannot start service celery: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"scripts/container_start.sh\": permission denied": unknown

ERROR: for web  Cannot start service web: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"scripts/container_start.sh\": permission denied": unknown
ERROR: Encountered errors while bringing up the project.

@codedsun
Copy link
Contributor Author

solution says to change the permission of bash file
ref: https://stackoverflow.com/a/46353378/6026355

@iamareebjamal
Copy link
Member

iamareebjamal commented Dec 23, 2019

That's because you needlessly changed ['sh', 'entrypoint'] to ['entrypoint']

As I have said countless times now, copy it as is until you understand it. DO NOT change something if you are not 100% sure why you're doing it. No idea why you make such changes

@codedsun
Copy link
Contributor Author

codedsun commented Dec 23, 2019

@iamareebjamal I am sorry but making mistakes are part of learning, as you said to change the
CMD ["sh", "scripts/container_start.sh"] to
ENTRYPOINT here #6690 (comment)

So what should be ENTRYPOINT ["command"] ?
I read this format of the ENTRYPOINT.

ENTRYPOINT ["sh", "scripts/container_start.sh"]

I am again sorry, but without the knowledge of docker. I would not have taken this task might be.

@iamareebjamal
Copy link
Member

Then it should have been just

-CMD
+ENTRYPOINT

@codedsun
Copy link
Contributor Author

do i need to remove the images or running docker-compose up --force-recreate will work for checking?

@codedsun
Copy link
Contributor Author

I am using docker for the first time, please ignore my mistakes as a learner. I had a hard time to understood this but I will learn it by working more on it. @iamareebjamal

Also, I am very excited by how the image process worked, it was amazing.

Thanks a lot! Everything working fine. Tested

@codedsun
Copy link
Contributor Author

tested ss:

image

@codedsun
Copy link
Contributor Author

@iamareebjamal Review please.

@iamareebjamal iamareebjamal changed the title chore:run container script run through CLI args chore: run container script run through CLI args Dec 23, 2019
@iamareebjamal iamareebjamal merged commit 03fa0ea into fossasia:development Dec 23, 2019
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.

Run container using CLI arguments instead of environment variables
2 participants