Skip to content

Commit

Permalink
feat: correctly working upload to remote (i hope)
Browse files Browse the repository at this point in the history
  • Loading branch information
SheezZarR committed Jan 22, 2024
1 parent ee153e1 commit 92280ad
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 100 deletions.
209 changes: 109 additions & 100 deletions .github/workflows/bot-cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,91 +13,96 @@ env:
IMAGE_NAME: ${{ github.repository }}

jobs:
# run-lint-and-formatting:
# # checks for common errors, code style consistency...
# runs-on: ubuntu-latest
# permissions:
# contents: write
# steps:
# - name: Checkout the repository
# uses: actions/checkout@v4
#
# - name: Setup python
# uses: actions/setup-python@v5
# with:
# python-version: '3.12'
#
# - name: Installing dependicies and running lint+formatting
# run: |
# make deps
# make lint

# - name: Check if changes happened...
# run: if [ -n "$(git status --porcelain)" ]; then export GIT_STATUS=1; else export GIT_STATUS=0; fi

# - name: Push changes
# if: ${{ env.GIT_STATUS == 1 }}
# run: |
# git config user.name github-actions
# git config user.email github-actions@github.com
# git add .
# git commit -m "Automated formatting and linting..."
# git push
#

# run-tests:
# needs: run-lint-and-formatting
# runs-on: ubuntu-latest
# permissions:
# contents: read
# steps:
# - name: Checkout the repository
# uses: actions/checkout@v4
#
# - name: Setup python
# uses: actions/setup-python@v5
# with:
# python-version: '3.12'
#
# - name: Installing deps
# run: make deps
#
# - name: Running tests
# run: pytest

# update-image:
# # update docker images if requirements are changed
# needs: run-tests
# runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write

# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Log in to the Container Registry
# uses: docker/login-action@v3
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - name: Extract metadata (tags, labels)
# id: meta
# uses: docker/metadata-action@v5
# with:
# images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# - name: Build and push Docker image
# uses: docker/build-push-action@v5
# with:
# context: .
# push: true
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}
# JOB 1
run-lint-and-formatting:
# checks for common errors, code style consistency...
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Installing dependicies and running lint+formatting
run: |
make deps
make lint
- name: Check if changes happened...
run: if [ -n "$(git status --porcelain)" ]; then export GIT_STATUS=1; else export GIT_STATUS=0; fi

- name: Push changes
if: ${{ env.GIT_STATUS == 1 }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "Automated formatting and linting..."
git push
# JOB 2
run-tests:
needs: run-lint-and-formatting
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Installing deps
run: make deps

- name: Running tests
run: pytest


# JOB 3
update-image:
# update docker images if requirements are changed
needs: run-tests
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


# JOB 4
update-remote:
# needs: update-image
runs-on: ubuntu-latest
Expand All @@ -116,33 +121,37 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Start SSH agent

- name: Put ssh key
run: |
mkdir -p ~/.ssh
touch ~/.ssh/id_ed25519
echo "$SSH_KEY" >> ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan $REMOTE_HOST >> ~/.ssh/known_hosts
- name: Start SSH agent and add the key
run: |
eval `ssh-agent -s`
mkdir ~/.ssh
touch ~/.ssh/telegram_bot
sudo chmod 600 ~/.ssh/telegram_bot
echo "$SSH_KEY" >> ~/.ssh/telegram_bot
ssh-add ~/.ssh/telegram_bot
ssh-add -vvv ~/.ssh/id_ed25519
- name: RSync prod compose
# archive, verbose, compress
run: |
rsync -avz -e 'ssh -p "$REMOTE_PORT"' --progress ./prod.docker-compose.yaml $REMOTE_USERNAME@$REMOTE_HOST:~/project/
rsync -avz -e "ssh -p ${REMOTE_PORT}" --progress ./prod.docker-compose.yml $REMOTE_USERNAME@$REMOTE_HOST:~/project/
- name: RSync environment variables in a file
run: |
echo $CONN_STRING >> .env
echo $TELEGRAM_TOKEN >> .env
rsync -avz -e 'ssh -p $REMOTE_PORT' --progress ./.env $REMOTE_USERNAME@$REMOTE_HOST:~/project/
echo "MONGO_CONNECT=${CONN_STRING}">> .env
echo "BOT_TOKEN=${TELEGRAM_TOKEN}" >> .env
rsync -avz -e "ssh -p ${REMOTE_PORT}" --progress ./.env $REMOTE_USERNAME@$REMOTE_HOST:~/project/
- name: Clear environment file
run: 'rm .env'
run: "rm .env"

- name: Run a compose file
run: |
ssh -p $REMOTE_PORT $REMOTE_USERNAME@$REMOTE_HOST
echo $GHCR_TOKEN >> docker login ghcr.io -u $DOCKER_USERNAME --password-stdin
docker compose -f ~/project/prod.docker-compose.yaml build
docker compose -f ~/project/prod.docker-compose.yaml up
ssh -p $REMOTE_PORT $REMOTE_USERNAME@$REMOTE_HOST "
echo $GHCR_TOKEN | docker login ghcr.io -u $DOCKER_USERNAME --password-stdin &&
docker compose -f ~/project/prod.docker-compose.yml build &&
docker compose -f ~/project/prod.docker-compose.yml up"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ venv/
ENV/
env.bak/
venv.bak/
.secret

# Spyder project settings
.spyderproject
Expand Down

0 comments on commit 92280ad

Please sign in to comment.