Skip to content

Commit

Permalink
fix: #dev-deploy tag fix 8
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinbator authored Dec 3, 2024
1 parent 402d6b5 commit c133a60
Showing 1 changed file with 108 additions and 98 deletions.
206 changes: 108 additions & 98 deletions .github/workflows/dev.kodemy.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,100 +36,100 @@ env:
JWT_KEY: ${{ secrets.JWT_KEY }}

jobs:
prepare:
name: Prepare
runs-on: self-hosted
environment: dev
steps:
- name: Check environments
run: |
REQUIRED_VARS=\
(
"WORKING_DIRECTORY"
"NETWORK_NAME"
"DATASOURCE_CONTAINER"
"DATASOURCE_USERNAME"
"DATASOURCE_PASSWORD"
"DATASOURCE_DB"
"RABBITMQ_HOST"
"RABBITMQ_PORT"
"RABBITMQ_USERNAME"
"RABBITMQ_PASSWORD"
"RABBITMQ_PASSWORD"
"ELASTICSEARCH_USERNAME"
"ELASTICSEARCH_PASSWORD"
"EUREKA_URL"
"FRONTEND_PUBLIC_HOST"
"CORS_ALLOWED_ORIGINS"
"GATEWAY_PUBLIC_HOST"
"OAUTH_GITHUB_ID"
"OAUTH_GITHUB_KEY"
"JWT_KEY"
"REDIS_HOST"
"REDIS_PORT"
)
EXIT=0
for VAR in "${REQUIRED_VARS[@]}"; do
[ -z "${!VAR}" ] && echo "Environment variable $VAR is missing." && EXIT=1
done
exit $EXIT
update-branch:
name: Update branch
needs: [ prepare ]
runs-on: self-hosted
environment: dev
steps:
- name: Update ${{ github.ref_name }}
uses: appleboy/ssh-action@master
env:
BRANCH: ${{ github.ref_name }}
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
port: ${{ secrets.REMOTE_PORT }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
envs: WORKING_DIRECTORY,BRANCH
script: |
cd $WORKING_DIRECTORY
git checkout $BRANCH || exit 1
git pull origin $BRANCH || exit 1
validate:
name: Validate services
runs-on: self-hosted
needs: [ update-branch ]
environment: dev
steps:
- name: Validate services
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
port: ${{ secrets.REMOTE_PORT }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
envs: WORKING_DIRECTORY,NETWORK_NAME,DATASOURCE_CONTAINER,DATASOURCE_USERNAME,DATASOURCE_DB
script: |
echo "Validate network"
docker network inspect $NETWORK_NAME > /dev/null 2>&1 \
|| { echo "Network $NETWORK_NAME is not available."; exit 1; }
# prepare:
# name: Prepare
# runs-on: self-hosted
# environment: dev
# steps:
# - name: Check environments
# run: |
# REQUIRED_VARS=\
# (
# "WORKING_DIRECTORY"
# "NETWORK_NAME"
# "DATASOURCE_CONTAINER"
# "DATASOURCE_USERNAME"
# "DATASOURCE_PASSWORD"
# "DATASOURCE_DB"
# "RABBITMQ_HOST"
# "RABBITMQ_PORT"
# "RABBITMQ_USERNAME"
# "RABBITMQ_PASSWORD"
# "RABBITMQ_PASSWORD"
# "ELASTICSEARCH_USERNAME"
# "ELASTICSEARCH_PASSWORD"
# "EUREKA_URL"
# "FRONTEND_PUBLIC_HOST"
# "CORS_ALLOWED_ORIGINS"
# "GATEWAY_PUBLIC_HOST"
# "OAUTH_GITHUB_ID"
# "OAUTH_GITHUB_KEY"
# "JWT_KEY"
# "REDIS_HOST"
# "REDIS_PORT"
# )
# EXIT=0
# for VAR in "${REQUIRED_VARS[@]}"; do
# [ -z "${!VAR}" ] && echo "Environment variable $VAR is missing." && EXIT=1
# done
# exit $EXIT
# update-branch:
# name: Update branch
# needs: [ prepare ]
# runs-on: self-hosted
# environment: dev
# steps:
# - name: Update ${{ github.ref_name }}
# uses: appleboy/ssh-action@master
# env:
# BRANCH: ${{ github.ref_name }}
# with:
# host: ${{ secrets.REMOTE_HOST }}
# username: ${{ secrets.REMOTE_USER }}
# port: ${{ secrets.REMOTE_PORT }}
# key: ${{ secrets.SSH_PRIVATE_KEY }}
# envs: WORKING_DIRECTORY,BRANCH
# script: |
# cd $WORKING_DIRECTORY
# git checkout $BRANCH || exit 1
# git pull origin $BRANCH || exit 1
# validate:
# name: Validate services
# runs-on: self-hosted
# needs: [ update-branch ]
# environment: dev
# steps:
# - name: Validate services
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.REMOTE_HOST }}
# username: ${{ secrets.REMOTE_USER }}
# port: ${{ secrets.REMOTE_PORT }}
# key: ${{ secrets.SSH_PRIVATE_KEY }}
# envs: WORKING_DIRECTORY,NETWORK_NAME,DATASOURCE_CONTAINER,DATASOURCE_USERNAME,DATASOURCE_DB
# script: |
# echo "Validate network"
# docker network inspect $NETWORK_NAME > /dev/null 2>&1 \
# || { echo "Network $NETWORK_NAME is not available."; exit 1; }

echo "Validate database - container"
docker exec -t $DATASOURCE_CONTAINER pg_isready \
|| { echo "PostgreSQL is not running."; exit 1; }
# echo "Validate database - container"
# docker exec -t $DATASOURCE_CONTAINER pg_isready \
# || { echo "PostgreSQL is not running."; exit 1; }

echo "Validate database - database"
docker exec -t $DATASOURCE_CONTAINER psql -lqt -U $DATASOURCE_USERNAME | grep -q $DATASOURCE_DB \
|| { echo "Database $DATASOURCE_DB does not exist."; exit 1; }
# echo "Validate database - database"
# docker exec -t $DATASOURCE_CONTAINER psql -lqt -U $DATASOURCE_USERNAME | grep -q $DATASOURCE_DB \
# || { echo "Database $DATASOURCE_DB does not exist."; exit 1; }

echo "Validate database - schemas"
DATASOURCE_SCHEMAS=("kodemy-auth" "kodemy-backend" "kodemy-notification")
for SCHEMA in "${DATASOURCE_SCHEMAS[@]}"
do
docker exec -t $DATASOURCE_CONTAINER psql \
-U $DATASOURCE_USERNAME \
-d $DATASOURCE_DB \
-tAc "SELECT 1 FROM information_schema.schemata WHERE schema_name = '$SCHEMA'" \
| grep -q 1 || { echo "Schema $SCHEMA does not exist."; exit 1; }
done
# echo "Validate database - schemas"
# DATASOURCE_SCHEMAS=("kodemy-auth" "kodemy-backend" "kodemy-notification")
# for SCHEMA in "${DATASOURCE_SCHEMAS[@]}"
# do
# docker exec -t $DATASOURCE_CONTAINER psql \
# -U $DATASOURCE_USERNAME \
# -d $DATASOURCE_DB \
# -tAc "SELECT 1 FROM information_schema.schemata WHERE schema_name = '$SCHEMA'" \
# | grep -q 1 || { echo "Schema $SCHEMA does not exist."; exit 1; }
# done

# build-and-deploy:
# name: Build, Test, Deploy
Expand Down Expand Up @@ -190,6 +190,7 @@ jobs:
create-tag:
name: Create tag
runs-on: self-hosted
environment: dev
steps:
- name: Determine new tag
id: tag
Expand All @@ -203,15 +204,24 @@ jobs:
echo "TAG_NAME=$new_tag" >> $GITHUB_ENV
- name: Create tag
uses: actions/github-script@v5
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
port: ${{ secrets.REMOTE_PORT }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${{ env.TAG_NAME }}`,
sha: context.sha
});
git tag ${{ env.TAG_NAME }}
git push origin --tags
# uses: actions/github-script@v5
# script: |
# github.rest.git.createRef({
# owner: context.repo.owner,
# repo: context.repo.repo,
# ref: `refs/tags/${{ env.TAG_NAME }}`,
# sha: context.sha
# });



Expand Down

0 comments on commit c133a60

Please sign in to comment.