forked from dqunbp/marblecutter-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
152 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ jobs: | |
uses: hotosm/gh-workflows/.github/workflows/[email protected] | ||
with: | ||
image_tags: | | ||
"ghcr.io/${{ github.repository }}:ci-${{ github.ref_name }}" | ||
"ghcr.io/${{ github.repository }}:${{ github.ref_name }}" | ||
invalidate-cache: | ||
runs-on: ubuntu-latest | ||
|
@@ -31,4 +31,4 @@ jobs: | |
gh actions-cache delete image-cache-${{ runner.os }} \ | ||
-R ${{ github.repository }} \ | ||
-B ${{ github.ref_name }} \ | ||
--confirm || true | ||
--confirm || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
FROM quay.io/mojodna/gdal:v2.3.x | ||
LABEL maintainer="[email protected]" | ||
FROM ghcr.io/osgeo/gdal:ubuntu-full-3.6.0 | ||
|
||
ARG http_proxy | ||
|
||
|
@@ -14,10 +13,12 @@ RUN apt-get update \ | |
git \ | ||
jq \ | ||
nfs-common \ | ||
build-essential \ | ||
parallel \ | ||
python-pip \ | ||
python-wheel \ | ||
python-setuptools \ | ||
python3 \ | ||
python3-dev \ | ||
python3-pip \ | ||
python3-setuptools \ | ||
unzip \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
@@ -34,17 +35,12 @@ ENV VSI_CACHE_SIZE 536870912 | |
ENV LC_ALL C.UTF-8 | ||
ENV LANG C.UTF-8 | ||
|
||
RUN apt-get update | ||
RUN apt-get install -y build-essential checkinstall | ||
RUN apt-get install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev | ||
RUN apt-get install -y wget | ||
RUN wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz | ||
RUN tar -xvf Python-3.6.3.tgz | ||
RUN cd Python-3.6.3 && ./configure && make && make install | ||
|
||
RUN pip3 install --upgrade setuptools | ||
RUN pip3 install rasterio haversine cython awscli | ||
RUN pip3 install rasterio haversine cython awscli requests | ||
|
||
COPY bin/* /opt/marblecutter-tools/bin/ | ||
|
||
RUN chmod +x /opt/marblecutter-tools/bin/process.sh | ||
RUN chmod +x /opt/marblecutter-tools/bin/process.py | ||
|
||
RUN ln -s /opt/marblecutter-tools/bin/* /usr/local/bin/ && mkdir -p /efs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env python3 | ||
# coding=utf-8 | ||
|
||
import subprocess | ||
import sys | ||
import requests | ||
import json | ||
import threading | ||
|
||
# Get command line arguments | ||
command_line_arguments = sys.argv[1:] | ||
|
||
# Construct the process command to execute | ||
process_command = ['bash', 'process.sh'] + command_line_arguments | ||
|
||
# Get the callback URL from the command line arguments | ||
callback_url = sys.argv[3] | ||
|
||
# Function to send a callback request | ||
|
||
|
||
def send_callback_request(body): | ||
response = requests.post(callback_url, json=body) | ||
|
||
# Start the subprocess and capture its standard error output | ||
|
||
|
||
def read_stream(stream, callback): | ||
while True: | ||
line = stream.readline() | ||
if line: | ||
callback(line) | ||
else: | ||
break | ||
|
||
|
||
# Initialize variables for parsing the subprocess's standard error output | ||
|
||
def stdout_callback(line): | ||
print(line) | ||
|
||
# Parse the standard error output line by line | ||
|
||
|
||
def stderr_callback(stderr_chunk): | ||
status_message_buffer = '' | ||
inside_status_tag = False | ||
error_message = '' | ||
|
||
i = 0 | ||
while i < len(stderr_chunk): | ||
# Check if the current character marks the start of a status message tag | ||
if stderr_chunk[i:i+2] == '#*': | ||
inside_status_tag = True | ||
i += 2 | ||
# Check if the current character marks the end of a status message tag | ||
elif stderr_chunk[i:i+2] == '*#': | ||
inside_status_tag = False | ||
# Extract the status message from the buffer and send a callback request if necessary | ||
text = status_message_buffer.strip() | ||
if text: | ||
print('Found status message:', text, flush=True) | ||
status_update_body = json.loads(text) | ||
if status_update_body["status"] == "failed": | ||
status_update_body["message"] = error_message | ||
send_callback_request(status_update_body) | ||
status_message_buffer = '' | ||
i += 2 | ||
# If inside a status message tag, append the current character to the buffer | ||
elif inside_status_tag: | ||
status_message_buffer += stderr_chunk[i] | ||
i += 1 | ||
# If not inside a status message tag, append the current character to the error message buffer | ||
else: | ||
error_message += stderr_chunk[i] | ||
i += 1 | ||
|
||
|
||
# Start the subprocess and capture its standard error output | ||
process_instance = subprocess.Popen( | ||
process_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) | ||
|
||
# Create separate threads for reading stdout and stderr | ||
stdout_thread = threading.Thread(target=read_stream, args=( | ||
process_instance.stdout, stdout_callback)) | ||
stderr_thread = threading.Thread(target=read_stream, args=( | ||
process_instance.stderr, stderr_callback)) | ||
|
||
# Start the threads | ||
stdout_thread.start() | ||
stderr_thread.start() | ||
|
||
# Wait for both threads to finish | ||
stdout_thread.join() | ||
stderr_thread.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.