Skip to content

Commit

Permalink
Fix/merge hotfix from prod (#57)
Browse files Browse the repository at this point in the history
- Correct typo errors in docker-compose.yml, docker-compose.prod.yml and docker-compose.override.yml for the use of default values
- Add keycloak build in CI and simplify keycloak image
- Correct traefik conf for taxapi service
- Add test to choose between docker-compose and docker compose command
  • Loading branch information
ophdlv authored Jan 6, 2024
1 parent 416f854 commit 0f0a266
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 51 deletions.
23 changes: 19 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ black:
build_api_development:
stage: build
script:
- docker login ${CI_REGISTRY} -u gitlab-ci-token -p ${CI_BUILD_TOKEN}
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- docker build --target development -t ${CI_REGISTRY_IMAGE}:api-dev ./api
- docker push ${CI_REGISTRY_IMAGE}:api-dev
only:
Expand All @@ -42,7 +42,7 @@ build_api_development:
build_api_production:
stage: build
script:
- docker login ${CI_REGISTRY} -u gitlab-ci-token -p ${CI_BUILD_TOKEN}
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- docker build --target production -t ${CI_REGISTRY_IMAGE}:api-latest ./api
- docker push ${CI_REGISTRY_IMAGE}:api-latest
only:
Expand All @@ -57,7 +57,7 @@ build_api_production:
build_frontend_development:
stage: build
script:
- docker login ${CI_REGISTRY} -u gitlab-ci-token -p ${CI_BUILD_TOKEN}
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- docker build --target development -t ${CI_REGISTRY_IMAGE}:frontend-dev ./frontend
- docker push ${CI_REGISTRY_IMAGE}:frontend-dev
only:
Expand All @@ -71,7 +71,7 @@ build_frontend_development:
build_frontend_production:
stage: build
script:
- docker login ${CI_REGISTRY} -u gitlab-ci-token -p ${CI_BUILD_TOKEN}
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- docker build --target production -t ${CI_REGISTRY_IMAGE}:frontend-latest ./frontend
- docker push ${CI_REGISTRY_IMAGE}:frontend-latest
only:
Expand All @@ -83,6 +83,21 @@ build_frontend_production:
tags:
- NSCICDDOCKER

build_keycloak:
stage: build
image:
name: gcr.io/kaniko-project/executor:v1.9.0-debug
entrypoint: [""]
script:
- /kaniko/executor --context "${CI_PROJECT_DIR}/keycloak" --dockerfile "${CI_PROJECT_DIR}/keycloak/Dockerfile" --destination "${CI_REGISTRY_IMAGE}:keycloak-${CI_COMMIT_REF_NAME}"
tags:
- NSCICDK8S
rules:
- if: '$CI_COMMIT_REF_NAME =~ /^(main|dev)$/ && $CI_PIPELINE_SOURCE == "push"'
changes:
- keycloak/**/*
- if: '$build_keycloak'

test_api:
stage: test
script:
Expand Down
2 changes: 1 addition & 1 deletion api/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
def on_startup():
init_bucket()

is_demo_instance = (os.environ.get("DEMO_INSTANCE", None) == "True")
is_demo_instance = os.environ.get("DEMO_INSTANCE", None) == "True"
if is_demo_instance:
init_db()
2 changes: 2 additions & 0 deletions docker/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ APP_USER=admin
APP_PASSWORD=password

# Database credentials
DB_IMAGE=postgres:14-alpine
DB_USER=dbuser
DB_PASSWORD=dbpassword
DB_NAME=annotation
Expand All @@ -28,6 +29,7 @@ MINIO_BUCKET_NAME=miniobucket
MINIO_IMAGE=minio/minio:RELEASE.2023-08-23T10-07-06Z

IMPORT_VARSUBSTITUTION_ENABLED=true
KEYCLOAK_IMAGE=registry.gitlab.com/natural-solutions/geonature/annotation:keycloak-dev
KEYCLOAK_REALM_ID=${PROJECT_NAME}
KEYCLOAK_CLIENT_ID=${PROJECT_NAME}
KEYCLOAK_TOKEN_URI=${CANONICAL_URL}/auth/realms/${KEYCLOAK_REALM_ID}/protocol/openid-connect/token
Expand Down
4 changes: 2 additions & 2 deletions docker/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ services:
- --providers.docker.exposedbydefault=false
- --entrypoints.web.address=:80
ports:
- ${TRAEFIK_PORT-8889}:80
- ${TRAEFIK_DASHBOARD_PORT-8890}:8080
- ${TRAEFIK_PORT:-8889}:80
- ${TRAEFIK_DASHBOARD_PORT:-8890}:8080

api:
build:
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ services:
minio:
labels:
- traefik.enable=true
- traefik.http.routers.minio.rule=Host(`${DOMAIN-my.domain.com}`) && PathPrefix(`/${MINIO_BUCKET_NAME-miniobucket}`)
- traefik.http.routers.minio.rule=Host(`${DOMAIN:-my.domain.com}`) && PathPrefix(`/${MINIO_BUCKET_NAME:-miniobucket}`)
- traefik.http.routers.minio.entrypoints=websecure
- traefik.http.routers.minio.tls=true
- traefik.http.routers.minio.tls.certresolver=le
72 changes: 38 additions & 34 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ x-project-defaults: &project_defaults
services:
traefik:
<<: *project_defaults
image: ${TRAEFIK_IMAGE-traefik:v2.6}
image: ${TRAEFIK_IMAGE:-traefik:v2.6}
depends_on:
frontend:
condition: service_healthy
Expand All @@ -21,7 +21,7 @@ services:

api:
<<: *project_defaults
image: ${API_IMAGE-registry.gitlab.com/natural-solutions/geonature/annotation:api-dev}
image: ${API_IMAGE:-registry.gitlab.com/natural-solutions/geonature/annotation:api-dev}
build:
context: ../api
dockerfile: Dockerfile
Expand All @@ -37,43 +37,42 @@ services:
condition: service_healthy
minio:
condition: service_healthy
keycloak:
keycloak:
condition: service_healthy
labels:
- traefik.enable=true
- traefik.http.routers.api.rule=${TRAEFIK_ROUTER_RULE_API-PathPrefix(`/api/v1`)}
- traefik.http.routers.api.rule=${TRAEFIK_ROUTER_RULE_API:-PathPrefix(`/api/v1`)}
- traefik.http.routers.api.entrypoints=web
- traefik.http.routers.api.middlewares=api-stripprefix
- traefik.http.middlewares.api-stripprefix.stripprefix.prefixes=${API_ROOT_PATH-/api/v1}
- traefik.http.middlewares.api-stripprefix.stripprefix.prefixes=${API_ROOT_PATH:-/api/v1}
environment:
- KEYCLOAK_ADMIN_CLIENT_SECRET=${KEYCLOAK_ADMIN_CLIENT_SECRET}
- KEYCLOAK_CALLBACK_URI=${KEYCLOAK_CALLBACK_URI-http://api:8000/callback}
- KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID-geonature-annotation}
- KEYCLOAK_CALLBACK_URI=${KEYCLOAK_CALLBACK_URI:-http://api:8000/callback}
- KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID:-geonature-annotation}
- KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET}
- KEYCLOAK_REALM=${KEYCLOAK_REALM-geonature-annotation}
- KEYCLOAK_SERVER_URL=${KEYCLOAK_SERVER_URL-http://keycloak:8080/auth}
- KEYCLOAK_REALM=${KEYCLOAK_REALM:-geonature-annotation}
- KEYCLOAK_SERVER_URL=${KEYCLOAK_SERVER_URL:-http://keycloak:8080/auth}
- KEYCLOAK_TOKEN_URI=${KEYCLOAK_TOKEN_URI}

taxapi:
<<: *project_defaults
image: ${TAXAPI_IMAGE-registry.gitlab.com/natural-solutions/geonature/taxapi:taxapi-latest}
image: ${TAXAPI_IMAGE:-registry.gitlab.com/natural-solutions/geonature/taxapi:taxapi-latest}
labels:
- traefik.enable=true
- traefik.http.routers.taxapi.rule=${TRAEFIK_ROUTER_RULE_TAXAPI-PathPrefix(`/taxapi`)}
- traefik.http.routers.taxapi.rule=${TRAEFIK_ROUTER_RULE_TAXAPI:-PathPrefix(`/taxapi`)}
- traefik.http.routers.taxapi.entrypoints=web
- traefik.http.middlewares.add-foo.addprefix.prefix=${TAXAPI_ROOT_PATH-/taxapi}
environment:
- TAXREF_FILE=${TAXAPI_TAXREF_FILE-TAXREF_v16_2022.zip}
- TAXREF_FILE=${TAXAPI_TAXREF_FILE:-TAXREF_v16_2022.zip}
healthcheck:
test: [ "CMD", "curl", "-f", "http://localhost:5666/taxapi/V1/healthcheck" ]
test: ["CMD", "curl", "-f", "http://localhost:5666/taxapi/V1/healthcheck"]
interval: 10s
timeout: 30s
retries: 5
start_period: 10s

frontend:
<<: *project_defaults
image: ${FRONTEND_IMAGE-registry.gitlab.com/natural-solutions/geonature/annotation:frontend-dev}
image: ${FRONTEND_IMAGE:-registry.gitlab.com/natural-solutions/geonature/annotation:frontend-dev}
build:
context: ../frontend
dockerfile: Dockerfile
Expand All @@ -88,7 +87,7 @@ services:
start_period: 60s
labels:
- traefik.enable=true
- traefik.http.routers.frontend.rule=${TRAEFIK_ROUTER_RULE_FRONTEND-PathPrefix(`/`)}
- traefik.http.routers.frontend.rule=${TRAEFIK_ROUTER_RULE_FRONTEND:-PathPrefix(`/`)}
- traefik.http.routers.frontend.entrypoints=web
environment:
- REACT_APP_KEYCLOAK_CLIENT_URL=${KEYCLOAK_CLIENT_URL:-http://localhost:8888/auth}
Expand All @@ -97,28 +96,33 @@ services:

db:
<<: *project_defaults
image: postgres:14-alpine
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER-dbuser} -d ${DB_NAME-annotation} -h 127.0.0.1"]
interval: 10s
timeout: 5s
retries: 3
image: ${DB_IMAGE:-postgres:14-alpine}
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -U ${DB_USER-dbuser} -d ${DB_NAME-annotation} -h 127.0.0.1",
]
interval: 10s
timeout: 5s
retries: 3
start_period: 60s
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD-dbpassword}
POSTGRES_DB: ${DB_NAME-annotation}
POSTGRES_USER: ${DB_USER-dbuser}
POSTGRES_PASSWORD: ${DB_PASSWORD:-dbpassword}
POSTGRES_DB: ${DB_NAME:-annotation}
POSTGRES_USER: ${DB_USER:-dbuser}

keycloak:
<<: *project_defaults
image: fastcam-keycloak-dev
image: ${KEYCLOAK_IMAGE:-registry.gitlab.com/natural-solutions/geonature/annotation:keycloak-dev}
build:
context: ../keycloak
command: start-dev --import-realm
command: start-dev --import-realm
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/auth"]
# https://github.com/keycloak/keycloak/issues/17273#issuecomment-1693549331
test: cat /proc/net/tcp | grep '00000000:1F90 00000000:0000' || exit 1
interval: 10s
timeout: 5s
retries: 10
Expand All @@ -128,23 +132,23 @@ services:
condition: service_healthy
labels:
- traefik.enable=true
- traefik.http.routers.keycloak.rule=${TRAEFIK_ROUTER_RULE_KEYCLOAK-PathPrefix(`/auth`)}
- traefik.http.routers.keycloak.rule=${TRAEFIK_ROUTER_RULE_KEYCLOAK:-PathPrefix(`/auth`)}
- traefik.http.routers.keycloak.entrypoints=web

minio:
<<: *project_defaults
image: ${MINIO_IMAGE-minio/minio:RELEASE.2023-08-23T10-07-06Z}
image: ${MINIO_IMAGE:-minio/minio:RELEASE.2023-08-23T10-07-06Z}
volumes:
- minio_data:/data
healthcheck:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
interval: 30s
timeout: 20s
retries: 3
command: server --console-address :9001 /data
labels:
- traefik.enable=true
- traefik.http.routers.minio.rule=${TRAEFIK_ROUTER_RULE_MINIO-PathPrefix(`/miniobucket`)}
- traefik.http.routers.minio.rule=${TRAEFIK_ROUTER_RULE_MINIO:-PathPrefix(`/miniobucket`)}

volumes:
db_data:
Expand Down
5 changes: 5 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ USER node
COPY --chown=node:node --from=deps /app/node_modules ./node_modules
COPY --chown=node:node . .

ARG REACT_APP_KEYCLOAK_CLIENT_URL
ARG REACT_APP_KEYCLOAK_CLIENT_REALM
ARG REACT_APP_KEYCLOAK_CLIENT_CLIENT_ID
ARG REACT_APP_API_PATH

RUN npm run build

EXPOSE 3000
Expand Down
Binary file added frontend/public/assets/geocam-logo-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/assets/geocam-logo-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/public/assets/geocam-logo-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/components/deviceMenu/deviceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ export default function DeviceModal() {
</Dialog>
</Grid>
);
}
}
1 change: 1 addition & 0 deletions frontend/src/components/importForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useMainContext } from "../contexts/mainContext";
import { DeploymentForProjectSheet, ProjectsService, ProjectWithDeployment } from "../client";
import { useParams } from "react-router-dom";
import { useTranslation } from "react-i18next";
import ButtonInteract from "./common/buttonInteract";


const ImportForm = (
Expand Down
5 changes: 0 additions & 5 deletions keycloak/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
FROM registry.access.redhat.com/ubi9 AS ubi-micro-build
RUN mkdir -p /mnt/rootfs
RUN dnf install --installroot /mnt/rootfs curl --releasever 9 --setopt install_weak_deps=false --nodocs -y; dnf --installroot /mnt/rootfs clean all

FROM quay.io/keycloak/keycloak:21.1.0

COPY --from=ubi-micro-build /mnt/rootfs /
COPY ./realm.json /opt/keycloak/data/import/realm.json
COPY ./theme/customtheme /opt/keycloak/themes/customtheme

Expand Down
14 changes: 12 additions & 2 deletions scripts/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ fi

PROJECT_NAME="geonature-annotation"

DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
VERSION_PARTS=(${DOCKER_VERSION//./ })

if ((${VERSION_PARTS[0]} < 24 || (${VERSION_PARTS[0]} == 0 && ${VERSION_PARTS[1]} < 0))); then
COMPOSE_COMMAND='docker-compose'
else
COMPOSE_COMMAND='docker compose'
fi


if [ "$ENV" == "production" ]; then
docker-compose --project-name=${PROJECT_NAME} -f ./docker/docker-compose.yml -f ./docker/docker-compose.prod.yml "$@"
$COMPOSE_COMMAND --project-name=${PROJECT_NAME} -f ./docker/docker-compose.yml -f ./docker/docker-compose.prod.yml "$@"
else
docker-compose --project-name=${PROJECT_NAME} --project-directory=./docker "$@"
$COMPOSE_COMMAND --project-name=${PROJECT_NAME} --project-directory=./docker "$@"
fi

0 comments on commit 0f0a266

Please sign in to comment.