Giter Club home page Giter Club logo

demos's Issues

Deployment in ECS Not successful (ECSBLOG-DEMO)

I followed the instructions and tried the deployment multiple times, but I always encounter an error on the provisioning of BackendService and LoadBalancer.

Screen Shot 2022-03-21 at 1 35 27 PM

I am not sure why this is happening, the AWS account that I am using has admin access.

address already in use

I watched the "Best Practices for Compose-managed Python Apps", thx for that! super informative and helpful.

I then tried to follow the same steps to debug the
project I'm working on: https://github.com/encointer/polkascan-os
My goal is to debug the explorer-api, which is a falcon (python) app.

So I:

  1. added the port 5678 in the docker-compose file.
  2. added the entry ptvsd==4.3.2 in the requirements.txt file
  3. added the code snipped ptvsd.enable_attach(address=('0.0.0.0',5678)) // why 0.0.0.0 here?
  4. docker-compose build and than docker-compose up
  5. in vscode, I added the configuration file with "localRoot": "${workspaceFolder}/explorer-api/app" and
    "remoteRoot": "/usr/src/app/app/" // here I add the folder that points to main.py, is this correct?

The error I'm getting is: OSError: [Errno 98] Address already in use

I struggle to understand, where the problem is, I guess somehow this port is already in use, but if i change the port, the same error appears which leads me to think, that somehow the debugger or so creates 2 instances that try to connect to that port.

I'm not sure this is the correct place to file the issue, if somebody knows a solution or a better place to get answers to my question, I'd be very thankful.

Here is the error message trace log (i get it 3x):

ptvsd.enable_attach(address=('0.0.0.0',5678))

File "/usr/local/lib/python3.8/site-packages/ptvsd/attach_server.py", line 101, in enable_attach
ptvsd_enable_attach(address)
File "/usr/local/lib/python3.8/site-packages/ptvsd/_remote.py", line 76, in enable_attach
pydevd.settrace(host=host,
File "/usr/local/lib/python3.8/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 2169, in settrace
_locked_settrace(
File "/usr/local/lib/python3.8/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 2230, in _locked_settrace
debugger.connect(host, port) # Note: connect can raise error.
File "/usr/local/lib/python3.8/site-packages/ptvsd/_vendored/pydevd/pydevd.py", line 1060, in connect
s = start_client(host, port)
File "/usr/local/lib/python3.8/site-packages/ptvsd/pydevd_hooks.py", line 136, in _start_client
return start_client(daemon, h, p)
File "/usr/local/lib/python3.8/site-packages/ptvsd/_remote.py", line 62, in
start_client=(lambda daemon, h, port: start_daemon()),
File "/usr/local/lib/python3.8/site-packages/ptvsd/_remote.py", line 50, in start_daemon
_, next_session = daemon.start_server(addr=(host, port))
File "/usr/local/lib/python3.8/site-packages/ptvsd/daemon.py", line 161, in start_server
self._server = create_server(addr.host, addr.port)
File "/usr/local/lib/python3.8/site-packages/ptvsd/socket.py", line 79, in create_server
server.bind((host, port))
OSError: [Errno 98] Address already in use

Suggestion to close the MySQL database cursor and connection in project/app/src/server.py

Anca,

Thank you for writing the 3 part series: Containerized Python Development These articles along with the references that you provided have been very helpful to me.

As a bit of a newbie to all things web and Docker, I see where after opening and reading the file handler for the password file...you later close the file. Great.

What I do not see is closing the cursor and connection for the MySQL database.

Maybe you could add the following methods in the class DBManager project/app/src/server.py

def cursor_close(self):
    self.cursor.close()

def connection_close(self):
    self.connection.close()

These methods could then be called after database activity has ended:

@server.route('/blogs')
def listBlog():
    global conn
    if not conn:
        conn = DBManager(password_file='/run/secrets/db-password')
        conn.populate_db()
    rec = conn.query_titles()

    result = []
    for c in rec:
        result.append(c)

    conn.cursor_close()
    conn.connection_close()
    conn = None

    return flask.jsonify({"response": result})

Mike

docker-compose up --build failed for ecsblog-demo on Ubuntu 22.04

~/samba/AWS/demos/ecsblog-demo$ docker-compose up --build
Building backend
Sending build context to Docker daemon 4.096kB
Step 1/7 : FROM python:3.7-alpine
---> cd2a4f346519
Step 2/7 : WORKDIR /app
---> Using cache
---> d7a2713b04cc
Step 3/7 : COPY requirements.txt /app
---> Using cache
---> 5e26a4331325
Step 4/7 : RUN pip3 install -r requirements.txt
---> Using cache
---> ceaeffece858
Step 5/7 : COPY main.py /app/main.py
---> Using cache
---> 4c4ceebc0966
Step 6/7 : ENTRYPOINT ["python3"]
---> Using cache
---> ea0f4de654cb
Step 7/7 : CMD ["/app/main.py"]
---> Using cache
---> 9dd4316e3ccd
Successfully built 9dd4316e3ccd
Successfully tagged ecsblog-demo_backend:latest

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Building frontend
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM nginx:alpine
---> 804f9cebfdc5
Step 2/2 : COPY nginx.conf /etc/nginx/conf.d/default.conf
---> Using cache
---> 484f90419a52
Successfully built 484f90419a52
Successfully tagged ecsblog-demo_frontend:latest

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Starting ecsblog-demo_backend_1 ... done
Starting ecsblog-demo_frontend_1 ... done
Attaching to ecsblog-demo_backend_1, ecsblog-demo_frontend_1
backend_1 | Traceback (most recent call last):
backend_1 | File "/app/main.py", line 1, in
backend_1 | from flask import Flask
backend_1 | File "/usr/local/lib/python3.7/site-packages/flask/init.py", line 14, in
backend_1 | from jinja2 import escape
backend_1 | ImportError: cannot import name 'escape' from 'jinja2' (/usr/local/lib/python3.7/site-packages/jinja2/init.py)
frontend_1 | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
frontend_1 | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
frontend_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
ecsblog-demo_backend_1 exited with code 1
frontend_1 | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
frontend_1 | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
frontend_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
frontend_1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
frontend_1 | /docker-entrypoint.sh: Configuration complete; ready for start up
frontend_1 | 2022/08/24 10:47:16 [emerg] 1#1: host not found in upstream "backend" in /etc/nginx/conf.d/default.conf:4
frontend_1 | nginx: [emerg] host not found in upstream "backend" in /etc/nginx/conf.d/default.conf:4
ecsblog-demo_frontend_1 exited with code 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.