Restructure the Message
class + Modify docstring
#15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Dockerhub Publish and Deploy on host | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- '.gitignore' | |
- '.pre-commit-config.yaml' | |
- '.github/**' | |
- 'docs/**' | |
- 'README.md' | |
jobs: | |
build-and-push-to-dockerhub: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Out Repo | |
uses: actions/checkout@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push Docker image using Docker Compose | |
run: | | |
docker compose build | |
docker compose push | |
deploy-on-host: | |
runs-on: ubuntu-latest | |
needs: [build-and-push-to-dockerhub] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up SSH | |
run: | | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" | base64 -d > ~/id_rsa | |
chmod 600 ~/id_rsa | |
- name: Deploy to Google Cloud | |
env: | |
BRANCH: main | |
CONTAINER_DIR: telegram-bot-protests-in-berlin | |
CONTAINER_NAME_1: postgres_db | |
CONTAINER_NAME_2: protestcrawler | |
CONTAINER_NAME_3: telegrambot | |
CONTAINER_NAME_4: tor_privoxy | |
TG_BOT_TOKEN: ${{secrets.TG_BOT_TOKEN}} | |
IP_ADDRESS: ${{secrets.SSH_HOST}} | |
SSL_PORT: ${{secrets.SSL_PORT}} | |
SSH_USERNAME: ${{ secrets.SSH_USERNAME }} | |
run: | | |
ssh-keyscan -t rsa $IP_ADDRESS >> ~/known_hosts | |
ssh -o UserKnownHostsFile=~/known_hosts \ | |
-i ~/id_rsa $SSH_USERNAME@$IP_ADDRESS \ | |
"export BRANCH=${{env.BRANCH}} \ | |
&& export CONTAINER_DIR=${{env.CONTAINER_DIR}} \ | |
&& export CONTAINER_NAME_1=${{env.CONTAINER_NAME_1}} \ | |
&& export CONTAINER_NAME_2=${{env.CONTAINER_NAME_2}} \ | |
&& export CONTAINER_NAME_3=${{env.CONTAINER_NAME_3}} \ | |
&& export CONTAINER_NAME_4=${{env.CONTAINER_NAME_4}} \ | |
&& export SSL_PORT=${{env.SSL_PORT}} \ | |
&& export TG_BOT_TOKEN=${{env.TG_BOT_TOKEN}} \ | |
&& export IP_ADDRESS=${{env.IP_ADDRESS}} \ | |
&& cd $CONTAINER_DIR \ | |
&& git fetch --all \ | |
&& git switch $BRANCH \ | |
&& git merge origin/$BRANCH \ | |
&& docker compose pull \ | |
&& docker compose down \ | |
&& docker system prune -af \ | |
&& docker compose up -d \ | |
&& echo Check whether the docker containers are running... \ | |
&& docker ps -q --filter name=^${CONTAINER_NAME_1}$ | grep -q . \ | |
&& docker ps -q --filter name=^${CONTAINER_NAME_2}$ | grep -q . \ | |
&& docker ps -q --filter name=^${CONTAINER_NAME_3}$ | grep -q . \ | |
&& docker ps -q --filter name=^${CONTAINER_NAME_4}$ | grep -q . \ | |
&& echo All docker containers are running." |