Portus | Authorization service and frontend for Docker registry | Continuous Deployment library
kandi X-RAY | Portus Summary
Support
Quality
Security
License
Reuse
- Perform an HTTP request .
- Internal handle error message .
- Returns a Markdown markdown text .
- Initialize the registry
- Change this role
- Destroy a repository
- Initializes the Registry
- Destroy a list of accounts
- Sets the owner of a user .
- Deletes the given namespace
Portus Key Features
Portus Examples and Code Snippets
Trending Discussions on Portus
Trending Discussions on Portus
QUESTION
EDIT: after playing around a little I realized that the issue is not related to the process variables, but to the fact that my server instance is executed only once for some reason. I'm still looking into it, I'll keep the post updated.
I am trying to get 100% coverage, but I'm stuck at testing this line:
const port = config.get("port") || process.env.PORT || 3000;
It seems that I can't set process.env.PORT
more than once.
const config = require("config");
// This checks if a port is being used
function portUsed(port) {
return new Promise((resolve, reject) => {
const net = require("net");
const server = net.createServer();
server.once("error", err => {
if (err.code === "EADDRINUSE") {
resolve(true);
}
});
server.once("listening", () => {
server.close();
resolve(false);
});
server.listen(port);
});
}
describe("index", () => {
// this works
it("should use process.env.PORT if config.get('port') is not set", async () => {
config.port = null;
process.env.PORT = 3333;
const server = require("../../index");
const result = await portUsed(3333);
expect(result).toBe(true);
await server.close();
});
// This does not work, but if you comment out / remove the previous test, it will work!
it("should default to port 3000 if other variables are not set", async () => {
config.port = null;
delete process.env.PORT;
const server = require("../../index");
const result = await portUsed(3000);
expect(result).toBe(true);
await server.close();
});
});
Basically only one of those two tests will run. What am I doing wrong?
index.js
const express = require("express");
const app = express();
const config = require("config");
const logger = require("./startup/logging");
require("./startup/console")(app);
require("./startup/database")();
require("./startup/routes")(app);
app.use(express.urlencoded({ extended: true }));
logger.info(config.get("name"));
// delete config.port;
// delete process.env.PORT;
// console.log("config", config.port);
console.log("server", process.env.PORT);
const port = config.get("port") || process.env.PORT || 3000;
const server = app.listen(port, () => logger.info(`Listening on port ${port}.`));
module.exports = server;
ANSWER
Answered 2020-Mar-17 at 03:27The reason why my test were not working is because the modules required (require("../../index.js")
) will be cached, hence only one instance of the server is created. To solve this just use:
beforeEach(() => jest.resetModules());
QUESTION
We have a private docker registry at work (based on portus, but whatever) and I try to push an image to this registry but it doesn't work. It fails with the following error message:
$ sudo docker login archive.docker-registry.mycompany.com
Username: mylogin
Password:
Error response from daemon: Get https://archive.docker-registry.mycompany.com/v1/users/:
net/http: TLS handshake timeout
$
I already configured the proxy in /etc/systemd/system/docker.service.d/http-proxy.conf (my docker is on centos 7):
[Service]
Environment="HTTP_PROXY=http://proxy.mycompany.com:8000/" "NO_PROXY=localhost,127.0.0.1,archive.docker-registry.mycompany.com"
but it still fails.
I tried to use HTTPS_PROXY instead of HTTP_PROXY using either http or https in url, I tried to download certificate manually and configure them in system (update-ca-certs) but it keeps failing.
When I changed this configuration file, as root, I executed:
# systemctl daemon-reload
# systemctl restart docker
ANSWER
Answered 2017-Apr-21 at 11:48actually, I found that if I comment out the full Environment line it works for the private registry but not for docker hub anymore (of course, no more proxy). And here is the final solution that works for both private registry and docker hub public registry:
In the NO_PROXY environment variable, only the domain name should be used, not the FQDN (including "archive." hostname prefix):
Here is my config file now:
[Service]
Environment="HTTP_PROXY=http://proxy.mycompany.com:8000/" "NO_PROXY=localhost,127.0.0.1,docker-registry.mycompany.com"
Note that there is no more "archive." nor "portus." prefix in NO_PROXY anymore, just the domain name starting from "docker-registry".
As I saw the docker login command line including "archive." prefix, it was misleading and I thought it had to be in the NO_PROXY environment variable... but no, it should not.
Hope it helps someone. I wish I found the answer on google before, but I didn't so I'm just posting it here, it might help someone.
QUESTION
I'm trying to get the target system port id using nmap module but getting list indices error
import nmap
nm_scan = nmap.PortScanner()
nm_scanner = nm_scan.scan('192.168.0.1', '80', arguments='-O')
print("Portid: " + nm_scanner['scan']['192.168.0.1']['portused']['portid'])
print("The host is: " + nm_scanner['scan']['192.168.0.1']['portused']['portid']) TypeError: list indices must be integers or slices, not str
print(nm_scanner)
{
'nmap': {
'command_line': 'nmap -oX - -p 80 -O 192.168.0.1',
'scaninfo': {
'tcp': {
'method': 'syn',
'services': '80'
}
},
'scanstats': {
'timestr': 'Fri Jul 26 11:31:30 2019',
'elapsed': '6.36',
'uphosts': '1',
'downhosts': '0',
'totalhosts': '1'
}
},
'scan': {
'192.168.0.1': {
'hostnames': [
{
'name': '',
'type': ''
}
],
'addresses': {
'ipv4': '192.168.0.1',
'mac': '1C:5F:2B:53:45:4F'
},
'vendor': {
'1C:5F:2B:53:45:4F': 'D-Link International'
},
'status': {
'state': 'up',
'reason': 'arp-response'
},
'uptime': {
'seconds': '87161',
'lastboot': 'Thu Jul 25 11:18:49 2019'
},
'tcp': {
80: {
'state': 'open',
'reason': 'syn-ack',
'name': 'http',
'product': '',
'version': '',
'extrainfo': '',
'conf': '3',
'cpe': ''
}
},
'portused': [
{
'state': 'open',
'proto': 'tcp',
'portid': '80'
},
{
'state': 'closed',
'proto': 'udp',
'portid': '42514'
}
],
'osmatch': [
{
'name': 'Allied Telesyn AT-GS950 or D-Link DES-3226L switch or D-Link DSL-2750U router',
'accuracy': '100',
'line': '2603',
'osclass': [
{
'type': 'switch',
'vendor': 'Allied Telesyn',
'osfamily': 'embedded',
'osgen': None,
'accuracy': '100',
'cpe': [
'cpe:/h:alliedtelesyn:at-gs950'
]
},
{
'type': 'switch',
'vendor': 'D-Link',
'osfamily': 'embedded',
'osgen': None,
'accuracy': '100',
'cpe': [
'cpe:/h:dlink:des-3226l',
'cpe:/h:dlink:dsl-2750u'
]
}
]
}
]
}
}
}
ANSWER
Answered 2019-Jul-26 at 06:02You are using string indices for nm_scanner and not numbers. Is nm_scanner a dictionary or list? You can know by saying the following.
type(nm_scanner)
If it is a list then you have to use numbers as index (in the square brackets). You can use string for dictionary. You can help us more by printing the nm_scanner and pasting here.
QUESTION
I am trying to recreate this project. What I have is a server (my computer), and a client (my raspberry pi). What I am doing differently than the original project is that I am trying to use a simple webcam instead of a raspberry pi camera to stream images from my rpi to the server. I know that I must:
- Get opencv image frames from the camera.
- Convert a frame (which is a numpy array) to bytes.
- Transfer the bytes from the client to the server.
- Convert the bytes back into frames and view.
Examples would be appreciated.
self_driver.py
import SocketServer
import threading
import numpy as np
import cv2
import sys
ultrasonic_data = None
#BaseRequestHandler is used to process incoming requests
class UltrasonicHandler(SocketServer.BaseRequestHandler):
data = " "
def handle(self):
while self.data:
self.data = self.request.recv(1024)
ultrasonic_data = float(self.data.split('.')[0])
print(ultrasonic_data)
#VideoStreamHandler uses streams which are file-like objects for communication
class VideoStreamHandler(SocketServer.StreamRequestHandler):
def handle(self):
stream_bytes = b''
try:
stream_bytes += self.rfile.read(1024)
image = np.frombuffer(stream_bytes, dtype="B")
print(image.shape)
cv2.imshow('F', image)
cv2.waitKey(0)
finally:
cv2.destroyAllWindows()
sys.exit()
class Self_Driver_Server:
def __init__(self, host, portUS, portCam):
self.host = host
self.portUS = portUS
self.portCam = portCam
def startUltrasonicServer(self):
# Create the Ultrasonic server, binding to localhost on port 50001
server = SocketServer.TCPServer((self.host, self.portUS), UltrasonicHandler)
server.serve_forever()
def startVideoServer(self):
# Create the video server, binding to localhost on port 50002
server = SocketServer.TCPServer((self.host, self.portCam), VideoStreamHandler)
server.serve_forever()
def start(self):
ultrasonic_thread = threading.Thread(target=self.startUltrasonicServer)
ultrasonic_thread.daemon = True
ultrasonic_thread.start()
self.startVideoServer()
if __name__ == "__main__":
#From SocketServer documentation
HOST, PORTUS, PORTCAM = '192.168.0.18', 50001, 50002
sdc = Self_Driver_Server(HOST, PORTUS, PORTCAM)
sdc.start()
video_client.py
import socket
import time
import cv2
client_sock = socket.socket()
client_sock.connect(('192.168.0.18', 50002))
#We are going to 'write' to a file in 'binary' mode
conn = client_sock.makefile('wb')
try:
cap = cv2.VideoCapture(0)
cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH,320)
cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT,240)
start = time.time()
while(cap.isOpened()):
conn.flush()
ret, frame = cap.read()
byteImage = frame.tobytes()
conn.write(byteImage)
finally:
finish = time.time()
cap.release()
client_sock.close()
conn.close()
ANSWER
Answered 2018-Aug-19 at 20:59You can't just display every received buffer of 1-1024 bytes as an image; you have to concatenate them up and only display an image when your buffer is complete.
If you know, out of band, that your images are going to be a fixed number of bytes, you can do something like this:
IMAGE_SIZE = 320*240*3
def handle(self):
stream_bytes = b''
try:
stream_bytes += self.rfile.read(1024)
while len(stream_bytes) >= IMAGE_SIZE:
image = np.frombuffer(stream_bytes[:IMAGE_SIZE], dtype="B")
stream_bytes = stream_bytes[IMAGE_SIZE:]
print(image.shape)
cv2.imshow('F', image)
cv2.waitKey(0)
finally:
cv2.destroyAllWindows()
sys.exit()
If you don't know that, you have to add some kind of framing protocol, like sending the frame size as a uint32 before each frame, so the server can know how many bytes to received for each frame.
Next, if you're just sending the raw bytes, without any dtype or shape or order information, you need to embed the dtype and shape information into the server. If you know it's supposed to be, say, bytes in C order in a particular shape, you can do that manually:
image = np.frombuffer(stream_bytes, dtype="B").reshape(320, 240, 3)
… but if not, you have to send that information as part of your framing protocol as well.
Alternatively, you could send a pickle.dumps
of the buffer and pickle.loads
it on the other side, or np.save
to a BytesIO
and np.load
the result. Either way, that includes the dtype, shape, order, and stride information as well as the raw bytes, so you don't have to worry about it.
The next problem is that you're exiting as soon as you display one image. Is that really what you want? If not… just don't do that.
But that just raises another problem. Do you really want to block the whole server with that cv.waitKey
? Your client is capturing images and sending them as fast as it can; surely you either want to make the server display them as soon as they arrive, or change the design so the client only sends frames on demand. Otherwise, you're just going to get a bunch of near-identical frames, then a many-seconds-long gap while the client is blocked waiting for you to drain the buffer, then repeat.
QUESTION
I am running a community edition of Docker (Version 18.03.1-ce-win65 (17513)) on Win10 with Linux containers option. I am building an image using docker locally on Windows, and pushing it to Portus, and finally accessing it to run from HPC running Linux using Putty. Well, it turns out that I am unable to run an instance of the created image because of the following error:
python: can't open file './Turn.py': [Errno 2] No such file or directory
This is my Dockerfile that I am using to build an image
FROM python:3.6
LABEL version="1.0"
LABEL build_date="xxx"
LABEL description="xxx"
COPY requirements.txt /
RUN pip install -r requirements.txt
ENV PYTHONIOENCODING UTF-8
# Set the default directory where CMD will execute on HPC
WORKDIR /turn
COPY Turn.py /Turn.py
CMD ["python", "./Turn.py"]
The build process completes successfully as indicated here:
Sending build context to Docker daemon 12.8kB
Step 1/13 : FROM python:3.6
---> 5f87764f9df0
Step 2/13 : LABEL maintainer="xxx"
---> Using cache
---> 71cd96de7015
Step 3/13 : LABEL version="1.0"
---> Using cache
---> 2fc5cdab38a9
Step 4/13 : LABEL build_date="xxx"
---> Using cache
---> ae488b87a931
Step 5/13 : LABEL description="xxx"
---> Using cache
---> cb11a0cf08a2
Step 6/13 : COPY requirements.txt /
---> Using cache
---> 5ec08f42d1f7
Step 7/13 : RUN pip install -r requirements.txt
---> Using cache
---> dfa45323647a
Step 8/13 : ENV PYTHONIOENCODING UTF-8
---> Using cache
---> 733907694a25
Step 9/13 : ENV http_proxy="http://xxx"
---> Using cache
---> 9b0ba73057ae
Step 10/13 : ENV https_proxy="https://xxx"
---> Using cache
---> e1ea75915df8
Step 11/13 : WORKDIR /turn
---> Using cache
---> a8b8ad69d82c
Step 12/13 : COPY Turn.py /Turn.py
---> Using cache
---> 9f9cb068c16b
Step 13/13 : CMD ["python", "./Turn.py"]
---> Using cache
---> a7f10949e521
Successfully built a7f10949e521
Successfully tagged turn:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
I am trying to run this image using the following command:
f@hpclogin1:~> docker run hpcdocker.hpc.xxx.com:5000/namespace/turn:latest
python: can't open file './Turn.py': [Errno 2] No such file or directory
ANSWER
Answered 2018-Jul-04 at 05:54This should be a simple path issue. Notice how you call python on ./turn.py
? This means you will assume it is a child of the current directory, which is - depending on your entrypoint - not necessarily the root folder where you copied it to.
Simply changing your call CMD ["python", "./Turn.py"]
CMD ["python", "/Turn.py"]
should resolve the issue.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Portus
On a UNIX-like operating system, using your system’s package manager is easiest. However, the packaged Ruby version may not be the newest one. There is also an installer for Windows. Managers help you to switch between multiple Ruby versions on your system. Installers can be used to install a specific or multiple Ruby versions. Please refer ruby-lang.org for more information.
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page