Skip to content

Commit

Permalink
Merge branch 'dev' into reader-18
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/build.yaml
#	.github/workflows/dev.yaml
  • Loading branch information
andyi95 committed Nov 22, 2023
2 parents d0cdf2c + ace637b commit b9e8b08
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 91 deletions.
119 changes: 48 additions & 71 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,96 +1,73 @@
name: deploy

on:
push:
branches:
- main

env:
DEPLOY_PATH: reader/
pull_request:
branches: [ main, dev ]

jobs:
deploy:
build-and-push:
name: Deploy images on the destination server
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check out the repo
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Copy env vars
uses: SpicyPizza/create-envfile@v1.3
- name: Login to DockerHub
uses: docker/login-action@v1
with:
envkey_DEBUG: true
envkey_SECRET_KEY: ${{ secrets.SECRET_KEY }}
envkey_TRAEFIK_BASIC_AUTH: ${{ secrets.TRAEFIK_BASIC_AUTH }}
envkey_TRAEFIK_API_HOST: ${{ secrets.TRAEFIK_API_HOST }}
envkey_IP_WHITELIST: ${{ secrets.IP_WHITELIST }}
envkey_COMPOSE_FILE: 'docker-compose.yaml'
envkey_COMPOSE_PROJECT_NAME: 'reader'
file_name: .env.dist
fail_on_empty: false
registry: registry.andyi95.com
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch

- name: Copy files to server
run: |
mkdir ../build
cp -TR . ../build
tar -cvf deploy.tar ../build/
- name: Set APP_VERSION
run: echo "APP_VERSION=$(echo ${GITHUB_SHA::8})" >> $GITHUB_ENV

- name: Deploy to server
uses: appleboy/scp-action@master
- name: Build and push frontend
uses: docker/build-push-action@v2
with:
host: ${{ secrets.HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
source: "deploy.tar"
target: "./"
create-envfile:
runs-on: ubuntu-latest
steps:
- name: Create env fie
uses: SpicyPizza/[email protected]
context: frontend
file: frontend/stage.Dockerfile
push: true
tags: registry.andyi95.com/text-tools/reading-frontend:${{ env.APP_VERSION }}
- name: Build and push backend
uses: docker/build-push-action@v2
with:
envkey_
context: backend
file: backend/Dockerfile
push: true
tags: registry.andyi95.com/text-tools/reading-backend:${{ env.APP_VERSION }}

- name: executing remote ssh commands to deploy
uses: appleboy/ssh-action@master
- name: Test start configuration
env:
IP_WHITELIST: ${{ secrets.IP_WHITELIST }}
TRAEFIK_BASIC_AUTH: ${{ secrets.TRAEFIK_BASIC_AUTH }}
TRAEFIK_API_HOST: ${{ secrets.TRAEFIK_API_HOST }}
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
envs: IP_WHITELIST,TRAEFIK_BASIC_AUTH,TRAEFIK_API_HOST
script: |
mkdir -p reader
tar -xvf deploy.tar --strip-components=1 -C reader/
mv -r reader/build/* reader/
cd reader/
echo "Building stage"
echo " "
env -i \
CI_ENVIRONMENT_DOMAIN=$CI_ENVIRONMENT_DOMAIN \
CI_PROJECT_NAME=$CI_PROJECT_NAME \
CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH \
bash -c '
set -a;
source .env.dist;
export DOCKER_USER="1000:1000"
(printenv | grep -v "^_=" | sort)
' > .env
echo "${{ secrets.ENV_FILE }}" >> .env
docker-compose build frontend
docker-compose run --rm -T frontend bash -c "npm install --no-save && npm run build"
docker-compose up -d --build --force-recreate --remove-orphans
COMPOSE_FILE: docker-compose.yaml:docker-compose.override.yaml:docker-compose.stage.yaml
run: |
docker-compose up -d
docker-compose ps
sleep 10
if [ $(docker-compose ps -q | wc -l) -ne $(docker-compose config --services | wc -l) ]; then
echo "Not all containers are running."
docker-compose ps
exit 1
fi
docker-compose down
send-telegram-message:
name: send-telegram-message
runs-on: ubuntu-latest
steps:
- name: send telegram message
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
message: |
Report on the last run of ${{ github.workflow }}.
${{ github.job }} in workflow ${{ github.action }} from repo ${{ github.repository }} has finished with status ${{ job.status }}.
${{ github.job }} in workflow ${{ github.action }} from repo ${{ github.repository }} has finished with status ${{ job.status }}.
30 changes: 10 additions & 20 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: Development version deploy

on:
push:
tags: [v*]
paths-ignore:
- 'README.md'
workflow_dispatch:


env:
DEPLOY_PATH: reader/
Expand All @@ -13,16 +11,17 @@ jobs:
build_and_push_to_docker_hub:
name: Build and push image to Docker Hub
runs-on: ubuntu-latest
environment: dev
strategy:
matrix:
include:
- dockerfile: frontend/stage.Dockerfile
context: frontend
image: registry.se.andyi95.com/text-tools/reading-frontend
image: registry.andyi95.com/text-tools/reading-frontend

- dockerfile: backend/Dockerfile
context: backend
image: registry.se.andyi95.com/text-tools/reading-backend
image: registry.andyi95.com/text-tools/reading-backend

steps:
- name: Check out the repo
Expand All @@ -47,7 +46,7 @@ jobs:
images: {{ matrix.image }}
tags:
type=sha, sha=${{ github.sha }}
type=semver,pattern={{version}}
type=ref,event={{branch}}

- name: Build and push frontend
uses: docker/build-push-action@v4
Expand All @@ -61,6 +60,7 @@ jobs:
deploy:
name: Deploy images on the destination server
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'}}
needs: build_and_push_to_docker_hub
steps:
- name: Copy files to server
Expand All @@ -72,7 +72,7 @@ jobs:
- name: Deploy to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.DEV_HOST }}
host: ${{ env.HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
Expand All @@ -90,7 +90,7 @@ jobs:
COMPOSE_FILE: 'docker-compose.yaml:docker-compose.stage.yaml'
COMPOSE_PROJECT_NAME: 'reader'
with:
host: ${{ secrets.DEV_HOST }}
host: ${{ env.HOST }}
username: ${{ secrets.USER }}
port: ${{ secrets.SSH_PORT }}
key: ${{ secrets.SSH_KEY }}
Expand All @@ -103,17 +103,7 @@ jobs:
docker-compose pull frontend backend
docker-compose up -d --force-recreate --remove-orphans
echo "Done"
# mv -r reader/build/* reader/
# cd reader/
# echo "Building stage"
# echo " "=
# bash -c '
# set -a;
# source .env.dist;
# (printenv | grep -v "^_=" | sort)
# ' > .env
# echo "${{ secrets.ENV_FILE }}" >> .env
# docker-compose up -d --force-recreate --remove-orphans
send_message:
name: send telegram message
runs-on: ubuntu-latest
Expand Down

0 comments on commit b9e8b08

Please sign in to comment.