diff --git a/.env b/.env new file mode 100644 index 0000000..84fb4ae --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +HCW_DOCTOR_VERSION=5.0.9 +HCW_ADMIN_VERSION=5.0.2 +HCW_BACKEND_VERSION=5.0.19 +HCW_PATIENT_VERSION=5.0.14 \ No newline at end of file diff --git a/.github/workflows/publish-hcw-docker-images.yml b/.github/workflows/publish-hcw-docker-images.yml index 8ceba81..140b5e1 100644 --- a/.github/workflows/publish-hcw-docker-images.yml +++ b/.github/workflows/publish-hcw-docker-images.yml @@ -37,6 +37,10 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Load .env file + id: dotenv + uses: ./.github/actions/dotenv-action + - name: Extract metadata (tags, labels) for Docker Admin id: meta-admin uses: docker/metadata-action@v5 @@ -44,8 +48,8 @@ jobs: images: | ${{ env.REGISTRY }}/${{ github.repository }}/${{ env.HCW_ADMIN_IMAGE_NAME }} tags: | - type=raw,value=${{ env.HCW_ADMIN_VERSION }}-${{ env.IMAGE_TAG }} - type=sha,prefix=${{ env.HCW_ADMIN_VERSION }}- + type=raw,value=${{ steps.dotenv.outputs.HCW_ADMIN_VERSION }}-${{ env.IMAGE_TAG }} + type=sha,prefix=${{ steps.dotenv.outputs.HCW_ADMIN_VERSION }}- - name: Extract metadata (tags, labels) for Docker Doctor id: meta-doctor diff --git a/README.md b/README.md index 2e65dae..5491a4b 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,15 @@ To provide custom translations, fork this repository and modify the `.over for each project, there is a folder named `assets/i18n` containing `.override.json` files. For instance for the patient interface, translations are in the folder [./patient/assets/i18n](./patient/assets/i18n). + +# How to update HCW versions generated by this repository and their related translations +- Change HCW versions in `.env` +- update translations by running the script `update-i18n-resources.sh` +- Do a PR to this repository + +The script `update-i18n-resources.sh` will update original json files in the folders `/assets/i18n`. +These files will be used in weblate. + # How to start the applications locally To test translations, all application can be started locally. diff --git a/admin/Dockerfile b/admin/Dockerfile index ae87678..0ea7a9c 100644 --- a/admin/Dockerfile +++ b/admin/Dockerfile @@ -1,11 +1,12 @@ ARG HCW_ADMIN_VERSION -FROM iabsis/hcw-admin:${HCW_ADMIN_VERSION} AS i18n-layer +FROM iabsis/hcw-admin:${HCW_ADMIN_VERSION} AS init-layer + +FROM init-layer AS i18n-layer USER root RUN apt update && apt install -y jq && rm -rf /var/lib/apt/lists/* COPY assets/* /usr/share/nginx/html/assets/i18n RUN bash /usr/share/nginx/html/assets/i18n/combine.sh -FROM iabsis/hcw-admin:${HCW_ADMIN_VERSION} - +FROM init-layer COPY --from=i18n-layer /usr/share/nginx/html/assets/i18n/*.json /usr/share/nginx/html/assets/i18n/ diff --git a/admin/assets/i18n/combine.sh b/admin/assets/i18n/combine.sh index 48e89df..140fe66 100755 --- a/admin/assets/i18n/combine.sh +++ b/admin/assets/i18n/combine.sh @@ -2,19 +2,22 @@ ## This script combine the language files # simply create a file .override.json and the overrided language -# will be applied on upgrade. folder=$(dirname $0) for file in ${folder}/??.json ; do - basename=$(echo ${file/.json/}) - filename=$(basename ${file}) + basename=$(echo "${file/.json/}") + filename=$(basename "${file}") lang=${filename/.json/} - if [ -f ${basename}.override.json ] ; then - jq -s '.[0] * .[1]' ${basename}.json ${basename}.override.json > ${basename}.combined.json ; ret=$? + if [ "${basename}" != "template" ] ; then + echo "Keep original file in ${basename}.orig.json" + cp "${basename}".json "${basename}".orig.json + fi + if [ -f "${basename}".override.json ] ; then + jq -s '.[0] * .[1]' "${basename}".json "${basename}".override.json > "${basename}".combined.json ; ret=$? if [ ${ret} = 0 ] ; then - mv ${basename}.json ${basename}.orig.json - mv ${basename}.combined.json ${basename}.json + mv "${basename}".combined.json "${basename}".json + rm "${basename}".override.json echo "Lang ${lang} combined successfully" else echo "Error during combining lang ${lang}, check if json is valid" diff --git a/backend/Dockerfile b/backend/Dockerfile index bb61867..a14818c 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,11 +1,12 @@ ARG HCW_BACKEND_VERSION -FROM iabsis/hcw-backend:${HCW_BACKEND_VERSION} AS i18n-layer +FROM iabsis/hcw-backend:${HCW_BACKEND_VERSION} AS init-layer +FROM init-layer AS i18n-layer USER root RUN apt update && apt install -y jq && rm -rf /var/lib/apt/lists/* COPY assets/* /usr/src/app/config/locales/ RUN bash /usr/src/app/config/locales/combine.sh -FROM iabsis/hcw-backend:${HCW_BACKEND_VERSION} +FROM init-layer COPY --from=i18n-layer /usr/src/app/config/locales/*.json /usr/src/app/config/locales/ diff --git a/backend/assets/i18n/combine.sh b/backend/assets/i18n/combine.sh index 48e89df..140fe66 100755 --- a/backend/assets/i18n/combine.sh +++ b/backend/assets/i18n/combine.sh @@ -2,19 +2,22 @@ ## This script combine the language files # simply create a file .override.json and the overrided language -# will be applied on upgrade. folder=$(dirname $0) for file in ${folder}/??.json ; do - basename=$(echo ${file/.json/}) - filename=$(basename ${file}) + basename=$(echo "${file/.json/}") + filename=$(basename "${file}") lang=${filename/.json/} - if [ -f ${basename}.override.json ] ; then - jq -s '.[0] * .[1]' ${basename}.json ${basename}.override.json > ${basename}.combined.json ; ret=$? + if [ "${basename}" != "template" ] ; then + echo "Keep original file in ${basename}.orig.json" + cp "${basename}".json "${basename}".orig.json + fi + if [ -f "${basename}".override.json ] ; then + jq -s '.[0] * .[1]' "${basename}".json "${basename}".override.json > "${basename}".combined.json ; ret=$? if [ ${ret} = 0 ] ; then - mv ${basename}.json ${basename}.orig.json - mv ${basename}.combined.json ${basename}.json + mv "${basename}".combined.json "${basename}".json + rm "${basename}".override.json echo "Lang ${lang} combined successfully" else echo "Error during combining lang ${lang}, check if json is valid" diff --git a/docker-compose.yml b/docker-compose.yml index b2c184e..607fbda 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: context: patient args: # If you update this, please update .github/workflows/publish-hcw-docker-images.yml - - HCW_PATIENT_VERSION=5.0.14 + - HCW_PATIENT_VERSION=$HCW_PATIENT_VERSION user: nginx ports: - "8080:8080" @@ -24,7 +24,8 @@ services: context: doctor args: # If you update this, please update .github/workflows/publish-hcw-docker-images.yml - - HCW_DOCTOR_VERSION=5.0.9 + - HCW_DOCTOR_VERSION=$HCW_DOCTOR_VERSION + # target: export-json user: nginx ports: - "8081:8081" @@ -39,7 +40,7 @@ services: context: admin args: # If you update this, please update .github/workflows/publish-hcw-docker-images.yml - - HCW_ADMIN_VERSION=5.0.2 + - HCW_ADMIN_VERSION=$HCW_ADMIN_VERSION user: nginx ports: - "8082:8082" @@ -54,7 +55,7 @@ services: context: backend args: #If you update this, please update .github/workflows/publish-hcw-docker-images.yml - - HCW_BACKEND_VERSION=5.0.19 + - HCW_BACKEND_VERSION=$HCW_BACKEND_VERSION user: node ports: - "1337:1337" @@ -95,12 +96,12 @@ services: - "3310:3310" mediasoup: - image: iabsis/mediasoup-api:latest - env_file: - - ./secrets.env - environment: - - API_USER=mediasoup_user - - REDIS_HOST=redis + image: iabsis/mediasoup-api:latest + env_file: + - ./secrets.env + environment: + - API_USER=mediasoup_user + - REDIS_HOST=redis volumes: diff --git a/doctor/Dockerfile b/doctor/Dockerfile index 353db11..b2cf6ee 100644 --- a/doctor/Dockerfile +++ b/doctor/Dockerfile @@ -1,11 +1,13 @@ ARG HCW_DOCTOR_VERSION -FROM iabsis/hcw-doctor:${HCW_DOCTOR_VERSION} AS i18n-layer +FROM iabsis/hcw-doctor:${HCW_DOCTOR_VERSION} AS init-layer + +FROM init-layer AS i18n-layer USER root RUN apt update && apt install -y jq && rm -rf /var/lib/apt/lists/* COPY assets/* /usr/share/nginx/html/assets/i18n RUN bash /usr/share/nginx/html/assets/i18n/combine.sh -FROM iabsis/hcw-doctor:${HCW_DOCTOR_VERSION} +FROM init-layer -COPY --from=i18n-layer /usr/share/nginx/html/assets/i18n/*.* /usr/share/nginx/html/assets/i18n/ +COPY --from=i18n-layer /usr/share/nginx/html/assets/i18n/*.json /usr/share/nginx/html/assets/i18n/ diff --git a/doctor/assets/i18n/combine.sh b/doctor/assets/i18n/combine.sh index 48e89df..140fe66 100755 --- a/doctor/assets/i18n/combine.sh +++ b/doctor/assets/i18n/combine.sh @@ -2,19 +2,22 @@ ## This script combine the language files # simply create a file .override.json and the overrided language -# will be applied on upgrade. folder=$(dirname $0) for file in ${folder}/??.json ; do - basename=$(echo ${file/.json/}) - filename=$(basename ${file}) + basename=$(echo "${file/.json/}") + filename=$(basename "${file}") lang=${filename/.json/} - if [ -f ${basename}.override.json ] ; then - jq -s '.[0] * .[1]' ${basename}.json ${basename}.override.json > ${basename}.combined.json ; ret=$? + if [ "${basename}" != "template" ] ; then + echo "Keep original file in ${basename}.orig.json" + cp "${basename}".json "${basename}".orig.json + fi + if [ -f "${basename}".override.json ] ; then + jq -s '.[0] * .[1]' "${basename}".json "${basename}".override.json > "${basename}".combined.json ; ret=$? if [ ${ret} = 0 ] ; then - mv ${basename}.json ${basename}.orig.json - mv ${basename}.combined.json ${basename}.json + mv "${basename}".combined.json "${basename}".json + rm "${basename}".override.json echo "Lang ${lang} combined successfully" else echo "Error during combining lang ${lang}, check if json is valid" diff --git a/patient/Dockerfile b/patient/Dockerfile index d8b04fe..5b7bc4e 100644 --- a/patient/Dockerfile +++ b/patient/Dockerfile @@ -1,11 +1,12 @@ ARG HCW_PATIENT_VERSION -FROM iabsis/hcw-patient:${HCW_PATIENT_VERSION} AS i18n-layer +FROM iabsis/hcw-patient:${HCW_PATIENT_VERSION} AS init-layer + +FROM init-layer AS i18n-layer USER root RUN apt update && apt install -y jq && rm -rf /var/lib/apt/lists/* COPY assets/* /usr/share/nginx/html/assets/i18n RUN bash /usr/share/nginx/html/assets/i18n/combine.sh -FROM iabsis/hcw-patient:${HCW_PATIENT_VERSION} - +FROM init-layer COPY --from=i18n-layer /usr/share/nginx/html/assets/i18n/*.json /usr/share/nginx/html/assets/i18n/ diff --git a/patient/assets/i18n/combine.sh b/patient/assets/i18n/combine.sh index 48e89df..140fe66 100755 --- a/patient/assets/i18n/combine.sh +++ b/patient/assets/i18n/combine.sh @@ -2,19 +2,22 @@ ## This script combine the language files # simply create a file .override.json and the overrided language -# will be applied on upgrade. folder=$(dirname $0) for file in ${folder}/??.json ; do - basename=$(echo ${file/.json/}) - filename=$(basename ${file}) + basename=$(echo "${file/.json/}") + filename=$(basename "${file}") lang=${filename/.json/} - if [ -f ${basename}.override.json ] ; then - jq -s '.[0] * .[1]' ${basename}.json ${basename}.override.json > ${basename}.combined.json ; ret=$? + if [ "${basename}" != "template" ] ; then + echo "Keep original file in ${basename}.orig.json" + cp "${basename}".json "${basename}".orig.json + fi + if [ -f "${basename}".override.json ] ; then + jq -s '.[0] * .[1]' "${basename}".json "${basename}".override.json > "${basename}".combined.json ; ret=$? if [ ${ret} = 0 ] ; then - mv ${basename}.json ${basename}.orig.json - mv ${basename}.combined.json ${basename}.json + mv "${basename}".combined.json "${basename}".json + rm "${basename}".override.json echo "Lang ${lang} combined successfully" else echo "Error during combining lang ${lang}, check if json is valid" diff --git a/update-i18n-resources.sh b/update-i18n-resources.sh new file mode 100644 index 0000000..30f2014 --- /dev/null +++ b/update-i18n-resources.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# This script will start docker services and copy initial i18n files for HCW Docker images. + +# copy file from docker service to the related i18n folder +move_files() { + local service=$1 + local docker_path=$2 + local tmp_folder="./${service}/assets/i18n-temp" + local i18n_folder="./${service}/assets/i18n" + rm -rf "${tmp_folder}" + docker compose cp "${service}":"${docker_path}" "${tmp_folder}" + echo "move ${tmp_folder}/template.json to ${i18n_folder}" + mv "${tmp_folder}"/template.json "${i18n_folder}"/ + for orig_file in "${tmp_folder}"/*.orig.json; do + target_name=$(basename "$orig_file"|cut -d. -f1)".json" + target_file=${i18n_folder}/$target_name + echo "Move ${orig_file} to ${target_file}" + mv "${orig_file}" "${target_file}" + done + rm -rf "${tmp_folder}" + +} + +docker compose up -d --build +move_files "doctor" "/usr/share/nginx/html/assets/i18n/" +move_files "admin" "/usr/share/nginx/html/assets/i18n/" +move_files "patient" "/usr/share/nginx/html/assets/i18n/" +move_files "backend" "/usr/src/app/config/locales/"