diff --git a/Makefile b/Makefile index 5a861572..046cf0f0 100644 --- a/Makefile +++ b/Makefile @@ -24,4 +24,5 @@ docker-container: docker build . -t ${CONT_TAG} podman-container: podman build . -t ${CONT_TAG} - +podman-container-devel: + podman build -f Dockerfile_dev -t pcw-devel diff --git a/README.md b/README.md index aed88a90..128ff4ff 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ The PCW container supports two volumes to be mounted: To create a container using e.g. the data directory `/srv/pcw` for both volumes and expose port 8000, run the following: - podman create --hostname pcw --name pcw -v /srv/pcw/pcw.ini:/etc/pcw.ini -v /srv/pcw/db:/pcw/db -p 8000:8000/tcp ghcr.io/suse/pcw:latest + podman create --hostname pcw --name pcw -v /srv/pcw/pcw.ini:/etc/pcw.ini -v /srv/pcw/db:/pcw/db -v :/var/pcw -p 8000:8000/tcp ghcr.io/suse/pcw:latest podman start pcw For usage in docker simply replace `podman` by `docker` in the above command. @@ -103,11 +103,21 @@ The `pcw` container runs by default the `/pcw/container-startup` startup helper podman exec pcw /pcw/container-startup help - podman run -ti --rm --hostname pcw --name pcw -v /srv/pcw/pcw.ini:/etc/pcw.ini -v /srv/pcw/db:/pcw/db -p 8000:8000/tcp ghcr.io/suse/pcw:latest /pcw/container-startup help + podman run -ti --rm --hostname pcw --name pcw -v /srv/pcw/pcw.ini:/etc/pcw.ini -v :/var/pcw -v /srv/pcw/db:/pcw/db -p 8000:8000/tcp ghcr.io/suse/pcw:latest /pcw/container-startup help To create the admin superuser within the created container named `pcw`, run - podman run -ti --rm -v /srv/pcw/pcw.ini:/etc/pcw.ini -v /srv/pcw/db:/pcw/db -p 8000:8000/tcp ghcr.io/suse/pcw:latest /pcw/container-startup createsuperuser --email admin@example.com --username admin + podman run -ti --rm -v /srv/pcw/pcw.ini:/etc/pcw.ini -v /srv/pcw/db:/pcw/db -v :/var/pcw -p 8000:8000/tcp ghcr.io/suse/pcw:latest /pcw/container-startup createsuperuser --email admin@example.com --username admin + +## Devel version of container + +There is [devel version](Dockerfile_dev) of container file. Main difference is that source files are not copied into image but expected to be mounted via volume. This ease development in environment close as much as possible to production run. + +Expected use would be : + + make podman-container-devel + podman run -v :/etc/pcw.ini -v :/var/pcw -v :/pcw -t pcw-devel + ## Codecov diff --git a/container-startup b/container-startup index ceccc34a..8b41ee42 100755 --- a/container-startup +++ b/container-startup @@ -51,4 +51,3 @@ case "$CMD" in *) python3 manage.py $@ esac - diff --git a/ocw/lib/EC2.py b/ocw/lib/EC2.py index af6a9ac3..dff87f65 100644 --- a/ocw/lib/EC2.py +++ b/ocw/lib/EC2.py @@ -69,10 +69,15 @@ def eks_client(self, region): return self.__eks_client[region] def all_clusters(self): - clusters = list() - for region in self.all_regions: + clusters = dict() + if PCWConfig.has('clusters/ec2_regions'): + cluster_regions = ConfigFile().getList('clusters/ec2_regions') + else: + cluster_regions = self.get_all_regions() + for region in cluster_regions: response = self.eks_client(region).list_clusters() - [clusters.append(cluster) for cluster in response['clusters']] + if len(response['clusters']): + clusters[region] = response['clusters'] return clusters @staticmethod diff --git a/ocw/lib/azure.py b/ocw/lib/azure.py index 3169bae0..970c13a2 100644 --- a/ocw/lib/azure.py +++ b/ocw/lib/azure.py @@ -42,7 +42,7 @@ def check_credentials(self): raise AuthenticationError("Invalid Azure credentials") def bs_client(self): - if(self.__blob_service_client is None): + if (self.__blob_service_client is None): storage_account = PCWConfig.get_feature_property( 'cleanup', 'azure-storage-account-name', self._namespace) storage_key = self.get_storage_key(storage_account) diff --git a/ocw/lib/cleanup.py b/ocw/lib/cleanup.py index d22c46c9..20bc1d86 100644 --- a/ocw/lib/cleanup.py +++ b/ocw/lib/cleanup.py @@ -34,7 +34,8 @@ def list_clusters(): for namespace in PCWConfig.get_namespaces_for('clusters'): try: clusters = EC2(namespace).all_clusters() - logger.info("%d clusters found", len(clusters)) + quantity = sum(len(c1) for c1 in clusters.keys()) + logger.info("%d clusters found", quantity) send_cluster_notification(namespace, clusters) except Exception as e: logger.exception("[{}] List clusters failed!".format(namespace)) diff --git a/ocw/lib/emailnotify.py b/ocw/lib/emailnotify.py index cd2686f7..fe20fff4 100644 --- a/ocw/lib/emailnotify.py +++ b/ocw/lib/emailnotify.py @@ -56,10 +56,13 @@ def send_leftover_notification(): def send_cluster_notification(namespace, clusters): if len(clusters) and PCWConfig.has('notify'): - clusters_str = ' '.join([str(cluster) for cluster in clusters]) + clusters_str = '' + for region in clusters: + clusters_list = ' '.join([str(cluster) for cluster in clusters[region]]) + clusters_str = '{}\n{} : {}'.format(clusters_str, region, clusters_list) logger.debug("Full clusters list - %s", clusters_str) - send_mail("EC2 clusters found", clusters_str, - receiver_email=PCWConfig.get_feature_property('cluster.notify', 'to', namespace)) + send_mail("[{}] EC2 clusters found".format(namespace), clusters_str, + receiver_email=PCWConfig.get_feature_property('notify', 'to', namespace)) def send_mail(subject, message, receiver_email=None): diff --git a/ocw/models.py b/ocw/models.py index 0d70b262..41a87696 100644 --- a/ocw/models.py +++ b/ocw/models.py @@ -63,7 +63,7 @@ def age_formated(self): return format_seconds(self.age.total_seconds()) def ttl_formated(self): - return format_seconds(self.ttl.total_seconds()) if(self.ttl) else "" + return format_seconds(self.ttl.total_seconds()) if (self.ttl) else "" def all_time_fields(self): all_time_pattern = "(age={}, first_seen={}, last_seen={}, ttl={})"