diff --git a/tools/dotcms-cli/action/.github/actions/dot-push/Dockerfile b/tools/dotcms-cli/action/.github/actions/dot-push/Dockerfile new file mode 100644 index 000000000000..130558f4671b --- /dev/null +++ b/tools/dotcms-cli/action/.github/actions/dot-push/Dockerfile @@ -0,0 +1,89 @@ +FROM openjdk:11 +LABEL authors="fabrizzioaraya" + +ARG CLI_RELEASE_DOWNLOAD_BASE_URL="https://github.com/dotCMS/core/releases/download/" +ARG RUN_JAVA_VERSION=1.3.8 +ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' +ARG RUN_DOT_CLI_VERSION='1.2.0' +ARG CLI_RELEASE_DOWNLOAD_URL="${CLI_RELEASE_DOWNLOAD_BASE_URL}dotcli${RUN_DOT_CLI_VERSION}/dotcli-${RUN_DOT_CLI_VERSION}.jar" +ENV DOT_CLI_JAR="dot-cli.jar" +ENV DEMO_API_URL="https://demo.dotcms.com/api" +ENV DOT_SERVICES_YML="dot-service.yml" +ENV ENTRYPOINT="entrypoint.sh" +ENV DOT_CLI_HOME=/dot-cli/ + +#the services yml is used to store the server configurations or profiles if you Will +ENV USER_HOME="/root/" +ENV DOT_SERVICES_HOME=${USER_HOME}".dotcms/" +#now move the file into the .dotcms folder located uder the user home folder +COPY ${DOT_SERVICES_YML} ${DOT_SERVICES_HOME} + +# Lets crate the dot-cli home folder and give it the right permissions +RUN mkdir -p ${DOT_CLI_HOME} +RUN chmod 777 ${DOT_CLI_HOME} +#Copy entry point +COPY ${ENTRYPOINT} ${DOT_CLI_HOME} + +#Tell the CLI to use the demo server +#The sufix value used to create the environment value must match the name on dot-service.yml file in this case we are using default +#dotcms.client.servers.default=https://demo.dotcms.com/api +ENV DOTCMS_CLIENT_SERVERS_DEFAULT=$DOT_API_URL +ENV DOTCMS_CLIENT_SERVERS_DEFAULT=${DOTCMS_CLIENT_SERVERS_DEFAULT:-$DEMO_API_URL} + +#Set the var that tells the CLI where to store the log file +ENV QUARKUS_LOG_FILE_PATH=${DOT_CLI_HOME}"dotcms-cli.log" + +# now lets get curl so we can download the CLI and the run-java.sh script +RUN apt-get update && \ + apt-get install -y curl && \ + apt-get clean; + +RUN echo "downloading dot CLI from ${CLI_RELEASE_DOWNLOAD_URL}" + +#Download the CLI from our relase repo and story as dot-cli.jar +RUN curl ${CLI_RELEASE_DOWNLOAD_URL} -L -o ${DOT_CLI_HOME}${DOT_CLI_JAR} +RUN chmod 777 "${DOT_CLI_HOME}${DOT_CLI_JAR}" + +#Check the size of the file +RUN file="${DOT_CLI_HOME}${DOT_CLI_JAR}" && \ + actual_size=$(wc -c <"$file"); + +RUN if (( $actual_size > 0 )); then \ + echo "dotcms-cli file size is $actual_size "; \ + else \ + echo "dot-CLI size is 0 bytes - Terminating program"; \ + exit 1; \ + fi + +RUN echo "downloading run-java.sh" +RUN curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o "${DOT_CLI_HOME}"run-java.sh +RUN chmod 777 ${DOT_CLI_HOME}run-java.sh + +#These environment vars are expected by the start-up script +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +# This is a relative path to the run-java.sh file, both the jar and script are expected to live in the same folder +ENV JAVA_APP_JAR="${DOT_CLI_JAR}" +# This is the name of the process that will be used to identify the process in the container +ENV JAVA_APP_NAME="dotcms-cli" + +# The following are here to enable debug mode +#ENV JAVA_DEBUG="y" +#ENV JAVA_DEBUG_SUSPEND="y" +#ENV JAVA_DEBUG_PORT="5005" +#EXPOSE 5005 + +# Code file to execute when the docker container starts up (`entrypoint.sh`) + +RUN echo "RUN_JAVA_VERSION IS ${RUN_JAVA_VERSION}" +RUN echo "DOT_CLI VERSION IS: ${RUN_DOT_CLI_VERSION}" +RUN echo "DOT_CLI_HOME IS: ${DOT_CLI_HOME}" +RUN echo "DOTCMS_CLIENT_SERVERS_DEFAULT IS: ${DOTCMS_CLIENT_SERVERS_DEFAULT}" +RUN echo "LOG FILE IS: ${QUARKUS_LOG_FILE_PATH}" + +RUN if [ -z "$secrets.DOT_TOKEN" ]; then \ + echo " No Access token has been provided!!"; \ + else \ + echo "A Token was found"; \ + fi + +ENTRYPOINT ["/dot-cli/entrypoint.sh"] \ No newline at end of file diff --git a/tools/dotcms-cli/action/.github/actions/dot-push/action.yml b/tools/dotcms-cli/action/.github/actions/dot-push/action.yml new file mode 100644 index 000000000000..a3f5095d7af1 --- /dev/null +++ b/tools/dotcms-cli/action/.github/actions/dot-push/action.yml @@ -0,0 +1,42 @@ +# dot-push.yml +name: 'dot-push' +description: 'Fire dotCMS cli' +inputs: + command: + description: 'super push command' + required: true + default: 'push' + path: + description: 'directory or file to push' + required: true + default: '/github/workspace/' + removeAssetsOption: + description: 'remove assets option' + required: false + default: '--removeAssets' + removeFoldersOption: + description: 'remove folders option' + required: false + default: '--removeFolders' + dotTokenOption: + description: 'dotCMS access token option' + required: true + default: '--token' + dotToken: + description: 'dotCMS access token' + required: true + +outputs: + return-code: # id of output. + description: 'Command return code' + +runs: + using: 'docker' + image: 'Dockerfile' + args: # ' push /github/workspace/contents --removeAssets --removeFolders --token 1234567890' + - ${{ inputs.command }} + - ${{ inputs.path }} + - ${{ inputs.removeAssetsOption }} + - ${{ inputs.removeFoldersOption }} + - ${{ inputs.dotTokenOption }} + - ${{ inputs.dotToken }} \ No newline at end of file diff --git a/tools/dotcms-cli/action/.github/actions/dot-push/dot-service.yml b/tools/dotcms-cli/action/.github/actions/dot-push/dot-service.yml new file mode 100644 index 000000000000..8ec11856a66a --- /dev/null +++ b/tools/dotcms-cli/action/.github/actions/dot-push/dot-service.yml @@ -0,0 +1,3 @@ +--- +- name: "default" + active: true \ No newline at end of file diff --git a/tools/dotcms-cli/action/.github/actions/dot-push/entrypoint.sh b/tools/dotcms-cli/action/.github/actions/dot-push/entrypoint.sh new file mode 100755 index 000000000000..cf8964a2951e --- /dev/null +++ b/tools/dotcms-cli/action/.github/actions/dot-push/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh + + ls -la /github/workspace/ + + var=$(bash /dot-cli/run-java.sh "$@" ) + #echo "var: $var" + echo "exit code: $?" + echo "Quarkus log file" + cat "${QUARKUS_LOG_FILE_PATH}" \ No newline at end of file diff --git a/tools/dotcms-cli/action/.github/actions/dot-workspace/Dockerfile b/tools/dotcms-cli/action/.github/actions/dot-workspace/Dockerfile new file mode 100644 index 000000000000..5de881a04950 --- /dev/null +++ b/tools/dotcms-cli/action/.github/actions/dot-workspace/Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu +LABEL authors="fabrizzioaraya" + +ENV DOT_WORKSPACE_YML=".dot-workspace.yml" +ENV FILES_NAME_SPACE="/files/" +ENV CONTENT_TYPES_NAME_SPACE="/content-types/" +ENV LANGS_NAME_SPACE="/languages/" +ENV SITES_NAME_SPACE="/sites/" +ENV DEFAULT_WORKSPACE_PATH="/github/workspace/" + +# Set environment variables based on inputs +ENV BASE_PATH=${INPUT_PATH:-$DEFAULT_WORKSPACE_PATH} +ENV CREATE_WORKSPACE=${INPUT_CREATE_WORKSPACE:-"true"} + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/tools/dotcms-cli/action/.github/actions/dot-workspace/action.yml b/tools/dotcms-cli/action/.github/actions/dot-workspace/action.yml new file mode 100644 index 000000000000..9d8c92471f70 --- /dev/null +++ b/tools/dotcms-cli/action/.github/actions/dot-workspace/action.yml @@ -0,0 +1,23 @@ +# dot-workspace.yml +name: 'dot-workspace' +description: 'creates an empty workspace if needed' +inputs: + path: + description: ' workspace' + required: true + default: 'true' + create-workspace: + description: 'create empty workspace' + required: true + default: 'true' + +outputs: + return-code: # id of output. + description: 'Command return code' + +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.path }} + - ${{ inputs.create-workspace }} \ No newline at end of file diff --git a/tools/dotcms-cli/action/.github/actions/dot-workspace/entrypoint.sh b/tools/dotcms-cli/action/.github/actions/dot-workspace/entrypoint.sh new file mode 100755 index 000000000000..ba89fee96deb --- /dev/null +++ b/tools/dotcms-cli/action/.github/actions/dot-workspace/entrypoint.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +if [ ! "$CREATE_WORKSPACE" = "true" ]; then + echo "Skipping workspace creation"; + exit 0; +fi + +normalize() { + in=$1 + normalized=$(echo "$in" | sed -E 's#/+#/#g') + echo "$normalized" +} + +BASE_PATH=$(normalize "$BASE_PATH") + +WORKSPACE_FILE=$BASE_PATH/$DOT_WORKSPACE_YML +WORKSPACE_FILE=$(normalize "$WORKSPACE_FILE") +echo "Workspace file: $WORKSPACE_FILE" + +workspace_file_content='name: default +version: 1.0.0 +description: "DO NOT ERASE ME !!! I am a marker file required by dotCMS CLI."' + +if [ ! -f "$WORKSPACE_FILE" ]; then + echo "Creating workspace file: $WORKSPACE_FILE"; + echo "$workspace_file_content" >> "$WORKSPACE_FILE"; + cat "$WORKSPACE_FILE"; +fi + +FILES_PATH=$BASE_PATH/$FILES_NAME_SPACE +FILES_PATH=$(normalize "$FILES_PATH") + +echo "Files path: $FILES_PATH" +if [ ! -f "$FILES_PATH" ]; then + echo "Creating files path: $FILES_PATH"; + mkdir -p "$FILES_PATH"; +fi + +CONTENT_TYPES_PATH=$BASE_PATH/$CONTENT_TYPES_NAME_SPACE +CONTENT_TYPES_PATH=$(normalize "$CONTENT_TYPES_PATH") + +echo "Content types path: $CONTENT_TYPES_PATH" +if [ ! -f "$CONTENT_TYPES_PATH" ]; then + echo "Creating content types path: $CONTENT_TYPES_PATH"; + mkdir -p "$CONTENT_TYPES_PATH"; +fi + +LANGUAGE_PATH=$BASE_PATH/$LANGS_NAME_SPACE +LANGUAGE_PATH=$(normalize "$LANGS_PATH") +echo "Languages path: $LANGUAGE_PATH" +if [ ! -f "$LANGUAGE_PATH" ]; then + echo "Creating languages path: $LANGUAGE_PATH"; + mkdir -p "$LANGUAGE_PATH"; +fi + +SITES_PATH=$BASE_PATH/$SITES_NAME_SPACE +SITES_PATH=$(normalize "$SITES_PATH") +echo "Sites path: $SITES_PATH" +if [ ! -f "$SITES_PATH" ]; then + echo "Creating sites path: $SITES_PATH"; + mkdir -p "$SITES_PATH"; +fi + +ls -la "$BASE_PATH" \ No newline at end of file diff --git a/tools/dotcms-cli/action/.github/workflows/main.yml b/tools/dotcms-cli/action/.github/workflows/main.yml new file mode 100644 index 000000000000..7982b6faa4d2 --- /dev/null +++ b/tools/dotcms-cli/action/.github/workflows/main.yml @@ -0,0 +1,64 @@ +name: dotCMS sync + +on: [push] + +jobs: + sync-with-dotcms: + runs-on: ubuntu-latest + env: + # Global environment expected by dotCMS CLI + # This is how we instruct the cli the target server + DOT_API_URL: ${{ vars.DOT_API_URL }} + # This is how we instruct the cli the target folder in the repo + # By default it must be the root of the repo which is represented by /github/workspace + DOT_REPO_BASE_PATH: ${{ vars.DOT_REPO_BASE_PATH || '/github/workspace/' }} + # This is how we instruct the cli to create the workspace if it does not exist + DOT_CREATE_WORKSPACE: ${{ vars.DOT_CREATE_WORKSPACE || 'true' }} + steps: + - name: Checkout + uses: actions/checkout@v3 + id: checkout + with: + fetch-depth: 0 + + - name: Get changes + id: changed-files + run: | + echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT + + - name: List changed files + run: | + for file in ${{ steps.changed-files.outputs.changed_files }}; do + echo "$file was changed" + done + + - name: Github Event Context properties + run: | + echo "Event: ${{ github.event }}" + echo "Event Name: ${{ github.event_name }}" + echo "Repository: ${{ github.repository }}" + echo "Commit SHA: ${{ github.sha }}" + echo "Commit Ref: ${{ github.ref }}" + echo "Head Ref: ${{ github.head_ref }}" + echo "Base Ref: ${{ github.base_ref }}" + echo "Triggered by: ${{ github.actor }}" + echo "Workflow: ${{ github.workflow }}" + echo "PR: ${{ github.pull_request }}" + + - name: Create workspace if not exists + uses: ./.github/actions/dot-workspace + id: dot-workspace + with: + path: ${{ env.DOT_REPO_BASE_PATH }} + create-workspace: ${{ env.DOT_CREATE_WORKSPACE }} + + - name: Trigger dot-push + uses: ./.github/actions/dot-push + id: dot-push + with: + command: 'push' + path: ${{ env.DOT_REPO_BASE_PATH }} + removeAssetsOption: '--removeAssets' + removeFoldersOption: '--removeFolders' + dotTokenOption: '--token' + dotToken: ${{ secrets.DOT_TOKEN }} \ No newline at end of file