Skip to content

Commit 59eca82

Browse files
Yuri ZmytrakovYuri Zmytrakov
authored andcommitted
Merge branch 'ops' into CAT-1413
2 parents cd5290e + 3c655cd commit 59eca82

File tree

9 files changed

+178
-7
lines changed

9 files changed

+178
-7
lines changed

.github/workflows/cicd.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
http.port: 9200
2727
xpack.license.self_generated.type: basic
2828
xpack.security.enabled: false
29+
plugins.security.ssl.http.enabled: "true"
2930
xpack.security.transport.ssl.enabled: false
3031
ES_JAVA_OPTS: -Xms512m -Xmx1g
3132
action.destructive_requires_name: false

.gitlab-ci.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
stages:
2+
- build
3+
# - tests
4+
# - tag_check
5+
- deploy
6+
7+
build:
8+
stage: build
9+
script: ./ci/build.sh
10+
tags:
11+
- kubernetes
12+
image:
13+
name: registry-public.cloudferro.com/kaniko-project/executor:v1.9.2-debug
14+
entrypoint: [ "" ]
15+
16+
#pytest:
17+
# stage: tests
18+
# image: python:3.13-slim
19+
# allow_failure: false
20+
# tags:
21+
# - kubernetes
22+
# services:
23+
# - name: opensearchproject/opensearch:2.11.1
24+
# alias: opensearch
25+
# variables:
26+
# cluster.name: "stac-cluster"
27+
# node.name: "os01"
28+
# discovery.type: "single-node"
29+
# plugins.security.disabled: "true"
30+
# action.destructive_requires_name: "false"
31+
# OPENSEARCH_JAVA_OPTS: "-Xms512m -Xmx1g"
32+
# before_script:
33+
# - ./ci/before_tests.sh
34+
# script:
35+
# - ./ci/pytest.sh
36+
# variables:
37+
# ENVIRONMENT: "testing"
38+
# ES_HOST: "opensearch"
39+
# ES_PORT: "9200"
40+
# ES_USE_SSL: "false"
41+
# ES_VERIFY_CERTS: "false"
42+
# BACKEND: "opensearch"
43+
# DATABASE_REFRESH: "true"
44+
# ENABLE_DATETIME_INDEX_FILTERING: "true"
45+
#
46+
# when: on_success
47+
48+
#tag_check:
49+
# stage: tag_check
50+
# script: ./ci/tag_image.sh
51+
# tags:
52+
# - kubernetes
53+
# image:
54+
# name: registry-public.cloudferro.com/kaniko-project/executor:v1.9.2-debug
55+
# entrypoint: [""]
56+
# only:
57+
# - tags
58+
59+
.deploy_template: &deploy_configuration
60+
stage: deploy
61+
image: registry.cloudferro.com/utils/docker_cache:alpine-latest
62+
when: manual
63+
allow_failure: false
64+
tags:
65+
- kubernetes
66+
67+
deploy-staging-cyrus:
68+
<<: *deploy_configuration
69+
variables:
70+
ARGOCD_APP_NAME: "stac-fastapi-os"
71+
script: ./ci/deploy.sh staging/cyrus
72+
73+
deploy-production-creo:
74+
<<: *deploy_configuration
75+
# only:
76+
# - tags
77+
variables:
78+
ARGOCD_APP_NAME: "stac-fastapi-os"
79+
script:
80+
- ./ci/deploy.sh prod/waw3-2-general-01

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM python:3.13-slim
2+
3+
RUN apt-get update && apt-get install -y \
4+
build-essential \
5+
&& apt-get clean \
6+
&& rm -rf /var/lib/apt/lists/*
7+
8+
WORKDIR /app
9+
10+
COPY README.md .
11+
COPY stac_fastapi/opensearch/setup.py stac_fastapi/opensearch/
12+
COPY stac_fastapi/core/setup.py stac_fastapi/core/
13+
COPY stac_fastapi/sfeos_helpers/setup.py stac_fastapi/sfeos_helpers/
14+
15+
16+
RUN pip install --no-cache-dir --upgrade pip setuptools wheel
17+
18+
COPY stac_fastapi/ stac_fastapi/
19+
20+
RUN pip install --no-cache-dir ./stac_fastapi/core
21+
RUN pip install --no-cache-dir ./stac_fastapi/sfeos_helpers
22+
RUN pip install --no-cache-dir ./stac_fastapi/opensearch[server]
23+
24+
EXPOSE 8080
25+
26+
CMD ["uvicorn", "stac_fastapi.opensearch.app:app", "--host", "0.0.0.0", "--port", "8080"]

ci/before_tests.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -e
3+
4+
apt-get update -y
5+
apt-get install -y build-essential curl openssh-client
6+
mkdir -p /root/.ssh/ && chmod 0700 /root/.ssh
7+
echo "${GITLAB_SSH_KEY}" > /root/.ssh/id_ed25519 && chmod 0600 /root/.ssh/id_ed25519
8+
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
9+
10+
pip install --upgrade pip setuptools wheel
11+
pip install ./stac_fastapi/core
12+
pip install ./stac_fastapi/sfeos_helpers
13+
pip install ./stac_fastapi/opensearch[dev,server]
14+
pip install pytest-timeout
15+
16+
echo "Waiting for OpenSearch"
17+
timeout 100 bash -c 'until curl -f http://opensearch:9200/_cluster/health; do sleep 5; done'
18+
echo "\nOpenSearch is ready"

ci/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
export DOCKER_IMAGE="${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}-${CI_PIPELINE_ID}"
6+
echo "Docker image -- $DOCKER_IMAGE"
7+
echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"},\"https://index.docker.io/v1/\":{\"auth\":\"$HUB_BASE64\"}}}" > /kaniko/.docker/config.json
8+
/kaniko/executor --build-arg=GITLAB_SSH_KEY --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $DOCKER_IMAGE;
9+
echo "Docker image -- $DOCKER_IMAGE"

ci/deploy.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if [ -z "$1" ]; then
6+
echo "Environment name is required. Possible options are: 'production-creo', 'production-lta'..."
7+
exit 1
8+
fi
9+
10+
11+
ENV=$1;
12+
13+
# Download operations repo and prepare for changes.
14+
apk add --no-cache git
15+
if [ -z "$CI_COMMIT_TAG" ]; then export APP_VERSION="${CI_COMMIT_REF_SLUG}-${CI_PIPELINE_ID}"; else APP_VERSION="${CI_COMMIT_TAG}"; fi
16+
if [ -z "$CI_COMMIT_TAG" ]; then export DOCKER_IMAGE="$CI_REGISTRY_IMAGE:${CI_COMMIT_REF_SLUG}-${CI_PIPELINE_ID}"; else DOCKER_IMAGE="$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG}"; fi
17+
git remote set-url origin https://oauth2:"${GITLAB_PUSH_TOKEN}"@gitlab.cloudferro.com/stac/operations.git
18+
git config --global user.email "[email protected]"
19+
git config --global user.name "GitLab CI/CD"
20+
git clone https://oauth2:"${GITLAB_PUSH_TOKEN}"@gitlab.cloudferro.com/stac/operations.git
21+
cd operations
22+
git checkout -B master
23+
24+
# Change deployment configuration operations.
25+
sed -i "s~'registry.cloudferro.com/stac/sfeos.*~'${DOCKER_IMAGE}',~" environments/"${ENV}"/stac-fastapi-os/main.jsonnet
26+
git add environments/"${ENV}"/stac-fastapi-os/main.jsonnet
27+
git commit -m "[${ENV}] stac-fastapi-os ${APP_VERSION}"
28+
git push origin master

ci/pytest.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Running OpenSearch tests"
5+
pytest -v --timeout=10 --log-cli-level=ERROR stac_fastapi/tests/

ci/tag_image.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
export DOCKER_IMAGE="${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG}-${CI_PIPELINE_ID}"
6+
export TAGGED_IMAGE="$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG}"
7+
echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"},\"https://index.docker.io/v1/\":{\"auth\":\"$HUB_BASE64\"}}}" > /kaniko/.docker/config.json
8+
echo "FROM $DOCKER_IMAGE TO $TAGGED_IMAGE"
9+
echo "FROM ${DOCKER_IMAGE}" | /kaniko/executor --context $CI_PROJECT_DIR --dockerfile /dev/stdin --destination ${TAGGED_IMAGE}
10+
echo "Docker image -- $TAGGED_IMAGE"

stac_fastapi/core/stac_fastapi/core/datetime_utils.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,11 @@ def normalize(dt):
2424
dt_obj = rfc3339_str_to_datetime(dt)
2525
dt_utc = dt_obj.astimezone(timezone.utc)
2626

27-
if dt_obj.microsecond > 0:
28-
return dt_utc.isoformat(timespec="milliseconds").replace("+00:00", "Z")
29-
else:
30-
return dt_utc.strftime("%Y-%m-%dT%H:%M:%SZ")
27+
return dt_utc.isoformat(timespec="milliseconds").replace("+00:00", "Z")
3128

3229
if not isinstance(date_str, str):
3330
return "../.."
3431

35-
if "/" in date_str and ".." in date_str:
36-
return date_str
37-
3832
if "/" not in date_str:
3933
return normalize(date_str)
4034

0 commit comments

Comments
 (0)