Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dev): add github action to deploy dev #135

Merged
merged 58 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c5785e9
fix(dev): add github action to deploy dev
bas-kirill Aug 28, 2024
2f8758c
fix(dev): add `redocly` installation at CD
bas-kirill Aug 28, 2024
5807eaf
fix(dev): remove `needs` due to development
bas-kirill Aug 28, 2024
3dea5df
fix(dev): add jvm temurin
bas-kirill Aug 28, 2024
4b5b57e
fix(dev): add jvm temurin
bas-kirill Aug 28, 2024
ee984a7
fiv(dev): do not use specific platforms for build
bas-kirill Aug 28, 2024
1816662
fiv(dev): do not use specific platforms for build
bas-kirill Aug 28, 2024
0dcf6df
fiv(dev): set up buildx
bas-kirill Aug 28, 2024
14d5dfa
fiv(dev): use local stage by default during deploy
bas-kirill Aug 28, 2024
68e5eb8
fiv(dev): add docker login step
bas-kirill Aug 28, 2024
852bfc3
fiv(dev): install dependencies
bas-kirill Aug 28, 2024
0dc8a7b
fix(dev): commit codegen
bas-kirill Aug 28, 2024
311cb74
fix(dev): commit codegen
bas-kirill Aug 28, 2024
56a8c63
fix(dev): pass user to github action
bas-kirill Aug 28, 2024
45f4433
fix(dev): use `--verbose`
bas-kirill Aug 28, 2024
4b32e74
fix(dev): remove leading slash
bas-kirill Aug 28, 2024
afe2edb
fix(dev): mkdir folder
bas-kirill Aug 28, 2024
1c3fa5e
fix(dev): mkdir folder
bas-kirill Aug 28, 2024
fb83026
fix(dev): mkdir folder
bas-kirill Aug 28, 2024
9eb27bf
chore(dev): add comment about issues and remove unreachable code
bas-kirill Aug 28, 2024
878ba01
chore(dev): remove debug logs
bas-kirill Aug 28, 2024
1a94f77
chore(dev): add echo current path
bas-kirill Aug 28, 2024
7d170a7
chore(dev): change node version
bas-kirill Aug 28, 2024
6ceb523
chore(dev): add debug log
bas-kirill Aug 28, 2024
7f3b480
chore(dev): add debug log
bas-kirill Aug 28, 2024
3f261d2
chore(dev): add `CI=false`
bas-kirill Aug 28, 2024
2e018c2
chore(dev): add `CI=false`
bas-kirill Aug 28, 2024
5e8110e
chore(dev): add npm cache
bas-kirill Aug 28, 2024
2c674d1
chore(dev): add SSH setup
bas-kirill Aug 28, 2024
8cbe32a
chore(dev): added DNS A name, rerun ssh setup
bas-kirill Aug 28, 2024
052b7e4
chore(dev): test SSH connection
bas-kirill Aug 29, 2024
4dda391
chore(dev): add docker context
bas-kirill Aug 29, 2024
b49a33e
chore(dev): regenerate private keys
bas-kirill Aug 29, 2024
8d6bf8a
chore(dev): do not use DNS for host
bas-kirill Aug 29, 2024
3f6defc
chore(dev): use ${MUSE_DOCKER_DEFAULT_CONTEXT}
bas-kirill Aug 29, 2024
0fb6b26
chore(dev): remove redundant code
bas-kirill Aug 29, 2024
85a1e4a
chore(dev): rerun
bas-kirill Aug 29, 2024
4c31562
chore(dev): rerun
bas-kirill Aug 29, 2024
4e00b75
chore(dev): return build
bas-kirill Aug 29, 2024
40c2d5a
chore(dev): use DNS name
bas-kirill Aug 29, 2024
675e429
chore(dev): comment build
bas-kirill Aug 29, 2024
2798323
chore(dev): use `shimataro/ssh-key-action@v2`
bas-kirill Aug 29, 2024
63808b7
chore(dev): use kiryuxa.com host
bas-kirill Aug 29, 2024
86bad45
chore(dev): ready ssh connection, uncomment build stage
bas-kirill Aug 29, 2024
328cbb3
chore(dev): add `SSH_USER` and `SSH_HOST`
bas-kirill Aug 29, 2024
9ad44c8
chore(dev): add leading slash to openapi generator path
bas-kirill Aug 29, 2024
3399e59
chore(dev): add path to client src generated
bas-kirill Aug 29, 2024
242d205
chore(dev): add folder creation
bas-kirill Aug 29, 2024
308994e
chore(dev): add folder creation
bas-kirill Aug 29, 2024
b76c69e
chore(dev): add docker pulling
bas-kirill Aug 29, 2024
4d9f868
chore(dev): remove folder creation for openapi generator
bas-kirill Aug 29, 2024
1bda140
chore(dev): add folder creation
bas-kirill Aug 29, 2024
7f7118f
chore(dev): add leading slash
bas-kirill Aug 29, 2024
6b9b7ad
chore(dev): remove openapi generation for client because it is alread…
bas-kirill Aug 29, 2024
f069e96
chore(dev): remove openapi generation for client because it is alread…
bas-kirill Aug 29, 2024
517ea62
chore(dev): remove multiplatform build
bas-kirill Aug 29, 2024
438fb3d
chore(dev): test deploy again
bas-kirill Aug 29, 2024
eaaf733
chore(dev): test deploy again
bas-kirill Aug 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading