Skip to content

Commit

Permalink
Merge pull request #135 from bas-kirill/feature/deploy-to-dev-github-…
Browse files Browse the repository at this point in the history
…action

fix(dev): add github action to deploy dev
  • Loading branch information
bas-kirill authored Aug 29, 2024
2 parents cfe018c + eaaf733 commit b95bd85
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 51 deletions.
61 changes: 47 additions & 14 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,29 +157,62 @@ jobs:

deploy-dev:
name: "[SERVER] Deploy to Dev"
needs:
- openapi-linter
- client-linter
- client-static-analyzer
- server-linter
- server-static-analyzer
- server-unit-tests
- server-sonarqube
# needs:
# - openapi-linter
# - client-linter
# - client-static-analyzer
# - server-linter
# - server-static-analyzer
# - server-unit-tests
# - server-sonarqube
runs-on: ubuntu-22.04
environment:
name: dev
url: http://dev.muse.kiryuxa.com
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: myshx
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up JDK 21 (Temurin)
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21.0"
- uses: actions/setup-node@v4
with:
node-version: "20.16.0"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: "Install `Redocly`"
run: npm i -g @redocly/cli@latest
- name: Cache npm dependencies
uses: actions/cache@v2
with:
path: '~/.npm'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
run: npm install --prefix client
- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.DEPLOY_SERVER_SSH_PRIVATE_KEY }}
known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
- name: Adding Known Hosts
run: ssh-keyscan -H kiryuxa.com >> ~/.ssh/known_hosts
- name: Deploy at home lab
run: ./tools/scripts/deploy/deployDev.sh myshx dev
run: echo "$(pwd)" && ./tools/scripts/deploy.sh dev
env:
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
SSH_HOST: ${{ secrets.DEV_SSH_HOST }}
SSH_PORT: ${{ secrets.DEV_SSH_PORT }}
SSH_USER: ${{ secrets.DEV_SSH_USER }}
SSH_PASS: ${{ secrets.DEV_SHH_PASS }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}
MUSE_DOCKER_DEFAULT_CONTEXT: default
MUSE_JWT_SECRET_KEY: ${{ secrets.MUSE_JWT_SECRET_KEY }}
CI: false # https://stackoverflow.com/questions/34917977/disable-npm-warnings-as-errors-build-definition-tfs
# deploy-staging:
# name: "[SERVER] Deploy to Staging"
# if: github.event.ref == 'refs/heads/main'
Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/edit-instrument/api/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const editInstrument = new EditInstrumentApi(apiConfig);
export const action: ActionFunction = async ({
request,
}): Promise<EditInstrumentAction> => {
return {
errors: [],
};
// return {
// errors: [],
// };

const {
instrumentId,
Expand Down
2 changes: 1 addition & 1 deletion client/src/shared/cookie/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getCookie(name: string) {
const value = "; " + document.cookie;
const parts = value.split("; " + name + "=");

if (parts.length == 2) {
if (parts.length === 2) {
return parts.pop()?.split(";").shift();
}
}
Expand Down
4 changes: 4 additions & 0 deletions tools/scripts/buildAndPush.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ fi
(cd "$rootDir" && exec ./tools/scripts/server/buildJar.sh)
(cd "$rootDir" && exec ./tools/scripts/server/buildImage.sh "$stage" "$dockerRepository")

echo "debug one"
(cd "$rootDir" && exec ./tools/scripts/client/build.sh "$stage")
echo "debug two"
(cd "$rootDir" && exec ./tools/scripts/client/buildDevImage.sh "$stage" "$dockerRepository")
echo "debug three"
(cd "$rootDir" && exec ./tools/scripts/client/buildImage.sh "$stage" "$dockerRepository" )
echo "debug four"
8 changes: 1 addition & 7 deletions tools/scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ docker context use "${MUSE_DOCKER_DEFAULT_CONTEXT}"
if [ "$stage" != "local" ]; then
context_name=muse-deploy-server
if ! docker context ls --format '{{.Name}}' | grep -q "^${context_name}$"; then
docker context create "${context_name}" --description "[MUSE] Deploy Server" --docker "host=ssh://[email protected]"
docker context create "${context_name}" --description "[MUSE] Deploy Server" --docker "host=ssh://${SSH_USER}@${SSH_HOST}"
fi

docker context use muse-deploy-server

function finish {
docker context use desktop-linux
}

trap 'finish' EXIT
fi

(cd "$rootDir/server" && exec ./gradlew clean)
Expand Down
2 changes: 2 additions & 0 deletions tools/scripts/client/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ if [ -z "$1" ]; then
echo -e "\033[0;33mNo stage provided. 'local' stage will be used.\033[0m"
fi

echo "kek"
export SERVER_API_URL="$(grep -w SERVER_API_URL "./tools/docker/env/$stage.env" | cut -d '=' -f2-)" # extract env variable by key
echo "SERVER_API_URL: '${SERVER_API_URL}'"
(cd "$rootDir" && npm --prefix "$rootDir/client" run build)

echo -e "\033[0;32mClient has been built.\033[0m"
1 change: 0 additions & 1 deletion tools/scripts/client/buildDevImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ fi

echo [MUSE CLIENT DEV] creating docker image "$imageFullName"...
(DOCKER_BUILDKIT=1 docker buildx build \
--platform linux/arm64,linux/amd64 \
-f "${rootDir}/client/Dockerfile.dev" \
-t "$imageFullName" \
"$rootDir" \
Expand Down
1 change: 0 additions & 1 deletion tools/scripts/client/buildImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ fi
echo [MUSE CLIENT] creating docker image "$imageFullName"...
(DOCKER_BUILDKIT=1 docker buildx build \
--no-cache \
--platform linux/arm64,linux/amd64 \
-f "${rootDir}/client/Dockerfile" \
-t "$imageFullName" \
"$rootDir" \
Expand Down
3 changes: 1 addition & 2 deletions tools/scripts/client/runLinter.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash
set -e
currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../../"

(cd "$rootDir/client" && echo "Current path: '$(pwd)'" && npx prettier . --check)
(cd "$rootDir/client" && npx prettier . --check)
(cd "$rootDir/client" && npx prettier . --write)
18 changes: 15 additions & 3 deletions tools/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ rootDir="$currentDir/../../"

[[ -z "${MUSE_DOCKER_DEFAULT_CONTEXT}" ]] && { echo "'MUSE_DOCKER_DEFAULT_CONTEXT' is not set. Exiting."; exit 1; }
[[ -z "${MUSE_JWT_SECRET_KEY}" ]] && { echo "'MUSE_JWT_SECRET_KEY' is not set. Exiting."; exit 1; }
[[ -z "${SSH_USER}" ]] && { echo "'SSH_USER' is not set. Exiting."; exit 1; }
[[ -z "${SSH_HOST}" ]] && { echo "'SSH_HOST' is not set. Exiting."; exit 1; }

trap 'docker context use "${MUSE_DOCKER_DEFAULT_CONTEXT}"' EXIT

Expand All @@ -18,8 +20,8 @@ fi
stage=$1

if [ -z "$1" ]; then
echo -e "\033[0;33mNo stage provided. 'DEV' stage will be used.\033[0m"
stage="dev"
echo -e "\033[0;33mNo stage provided. 'local' stage will be used.\033[0m"
stage="local"
fi

dockerRepository=$2
Expand All @@ -29,7 +31,17 @@ if [ -z "$2" ]; then
dockerRepository="myshx"
fi

(cd "$rootDir" && exec ./tools/scripts/openapi/regenerateOpenApi.sh)
if [ "$stage" != "local" ]; then
context_name=muse-$stage
if ! docker context ls --format '{{.Name}}' | grep -q "^${context_name}$"; then
docker context create "${context_name}" --description "[MUSE] '$stage' Deploy Server" --docker "host=ssh://${SSH_USER}@${SSH_HOST}"
fi

docker context use "$context_name"
fi

# do not regenerate OpenAPI due to it is already committed to repo
#(cd "$rootDir" && exec ./tools/scripts/openapi/regenerateOpenApi.sh)
(cd "$rootDir" && exec ./tools/scripts/buildAndPush.sh "$stage" "$dockerRepository")
(cd "$rootDir" && exec ./tools/scripts/stop.sh "$stage" "$dockerRepository")
(cd "$rootDir" && exec ./tools/scripts/clean.sh "$stage" "$dockerRepository")
Expand Down
30 changes: 20 additions & 10 deletions tools/scripts/openapi/regenerateOpenApi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@ currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../../"

(cd "$rootDir" && exec ./tools/scripts/openapi/bundle.sh)
(cd "$rootDir/client" && rm -rf ./src/generated)
(cd "$rootDir" && exec docker run \
--rm \
-v "${PWD}/openapi:/local/openapi" \
-v "${PWD}/client/src/generated:/local/client/src/generated" \
openapitools/openapi-generator-cli:v7.8.0 generate \
--input-spec /local/openapi/openapi.yml \
--output /local/client/src/generated \
--generator-name typescript-axios \
--additional-properties=apiPackage=api,modelPackage=model,supportsES6=true,withSeparateModelsAndApi=true
(cd "$rootDir" && rm -rf ./client/src/generated)

# https://github.com/OpenAPITools/openapi-generator/issues/12191
(cd "$rootDir" && docker pull openapitools/openapi-generator-cli:v7.8.0)
(cd "$rootDir" &&
docker run \
--rm \
-v "${PWD}:/local" \
-u "$(id -u)":"$(id -g)" \
openapitools/openapi-generator-cli:v7.8.0 generate \
--input-spec local/openapi/openapi.yml \
--output local/client/src/generated \
--generator-name typescript-axios \
--additional-properties=apiPackage=api,modelPackage=model,supportsES6=true,withSeparateModelsAndApi=true
)

# mkdir local &&
# mkdir -p local/client/src/generated/model &&
# mkdir -p /local/client/src/generated/model &&

(cd "$rootDir/server" && ./gradlew clean)
(cd "$rootDir/server" && ./gradlew openApiGenerate)
(cd "$rootDir" && ./tools/scripts/client/runLinter.sh)

echo -e "\033[0;32mOpenAPI specs has been regenerated.\033[0m"
10 changes: 3 additions & 7 deletions tools/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ rootDir="$currentDir/../../"

[[ -z "${MUSE_DOCKER_DEFAULT_CONTEXT}" ]] && { echo "'MUSE_DOCKER_DEFAULT_CONTEXT' is not set. Exiting."; exit 1; }
[[ -z "${MUSE_JWT_SECRET_KEY}" ]] && { echo "'MUSE_JWT_SECRET_KEY' is not set. Exiting."; exit 1; }
[[ -z "${SSH_USER}" ]] && { echo "'SSH_USER' is not set. Exiting."; exit 1; }
[[ -z "${SSH_HOST}" ]] && { echo "'SSH_HOST' is not set. Exiting."; exit 1; }

trap 'docker context use "${MUSE_DOCKER_DEFAULT_CONTEXT}"' EXIT

Expand All @@ -27,16 +29,10 @@ docker context use "${MUSE_DOCKER_DEFAULT_CONTEXT}"
if [ "$stage" != "local" ]; then
context_name=muse-$stage
if ! docker context ls --format '{{.Name}}' | grep -q "^${context_name}$"; then
docker context create "${context_name}" --description "[MUSE $stage] Deploy Server" --docker "host=ssh://[email protected]"
docker context create "${context_name}" --description "[MUSE $stage] Deploy Server" --docker "host=ssh://${SSH_USER}@${SSH_HOST}"
fi

docker context use "$context_name"

function finish {
docker context use desktop-linux
}

trap "finish" EXIT
fi

export DOCKER_REPOSITORY=$dockerRepository
Expand Down
1 change: 0 additions & 1 deletion tools/scripts/server/buildImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ fi

echo "[MUSE SERVER] creating docker image '$imageFullName'..."
(DOCKER_BUILDKIT=1 docker buildx build \
--platform linux/arm64,linux/amd64 \
-f "${rootDir}/server/Dockerfile" \
-t "$imageFullName" \
"$rootDir" \
Expand Down
4 changes: 3 additions & 1 deletion tools/scripts/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ currentDir=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
rootDir="$currentDir/../../"

[[ -z "${MUSE_DOCKER_DEFAULT_CONTEXT}" ]] && { echo "'MUSE_DOCKER_DEFAULT_CONTEXT' is not set. Exiting."; exit 1; }
[[ -z "${SSH_USER}" ]] && { echo "'SSH_USER' is not set. Exiting."; exit 1; }
[[ -z "${SSH_HOST}" ]] && { echo "'SSH_HOST' is not set. Exiting."; exit 1; }

trap 'docker context use "${MUSE_DOCKER_DEFAULT_CONTEXT}"' EXIT

Expand All @@ -26,7 +28,7 @@ docker context use "${MUSE_DOCKER_DEFAULT_CONTEXT}"
if [ "$stage" != "local" ]; then
context_name=muse-$stage
if ! docker context ls --format '{{.Name}}' | grep -q "^${context_name}$"; then
docker context create "${context_name}" --description "[MUSE] '$stage' Deploy Server" --docker "host=ssh://[email protected]"
docker context create "${context_name}" --description "[MUSE] '$stage' Deploy Server" --docker "host=ssh://${SSH_USER}@${SSH_HOST}"
fi

docker context use "$context_name"
Expand Down

0 comments on commit b95bd85

Please sign in to comment.