From d97585900c72284e9e36b09afd32ce021cf6a303 Mon Sep 17 00:00:00 2001 From: Deko Date: Fri, 3 Mar 2023 22:20:00 +0100 Subject: [PATCH] Add deploy step, update readme, copy less files to image --- .env.example | 2 +- .gitignore | 3 ++- .gitlab-ci.yml | 34 ++++++++++++++++++++++++++++++++++ Dockerfile | 5 ++++- README.md | 6 +++++- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 894e17f..608cc65 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ STREAMER_NAME="example" DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..." TWITCH_CLIENT_ID="" -TWITCH_CLIENT_SECRET="" \ No newline at end of file +TWITCH_CLIENT_SECRET="" diff --git a/.gitignore b/.gitignore index 13d4ac5..8b11ccf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .env -.idea/ \ No newline at end of file +.idea/ +.idea/vcs.xml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 403b403..b18843c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ stages: - lint - build + - deploy .install-deps-script: &install-deps - curl -sSL https://install.python-poetry.org | python - @@ -17,6 +18,12 @@ stages: before_script: - *install-deps +###################################### +# # +# LINT STEPS # +# # +###################################### + black: extends: .lint script: @@ -27,6 +34,11 @@ isort: script: - poetry run isort --check . +###################################### +# # +# BUILD STEPS # +# # +###################################### build: stage: build @@ -43,3 +55,25 @@ build: - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker build -f Dockerfile -t $IMAGE_TAG --build-arg version=$CI_COMMIT_SHA . - docker push $IMAGE_TAG + +###################################### +# # +# DEPLOY STEPS # +# # +###################################### + +deploy: + stage: deploy + image: alpine:latest + before_script: + - 'command -v ssh-agent >/dev/null || ( apk add --update openssh )' + - eval $(ssh-agent -s) + - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - ssh-keyscan $REMOTE_HOST >> ~/.ssh/known_hosts + - chmod 644 ~/.ssh/known_hosts + script: + - ssh $SSH_USER@$REMOTE_HOST "bash -c 'cd /home/raphael/twitch-notifier && ./start.sh'" + only: + - main diff --git a/Dockerfile b/Dockerfile index 7cbb09c..814af90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ FROM python:3.11.2 -COPY ./ / +COPY /poetry.lock /poetry.lock +COPY /pyproject.toml /pyproject.toml +COPY ./app /app + WORKDIR / RUN apt-get update RUN apt-get -y dist-upgrade diff --git a/README.md b/README.md index 607d29f..95878f2 100644 --- a/README.md +++ b/README.md @@ -55,4 +55,8 @@ python app/main.py ## Running in Docker -The second option is to run the project's docker image. \ No newline at end of file +The second option is to run the project's docker image. + +You have two paths you can take here as well: +1. You may fork the project and use the configured pipelines and container registry. +2. You may build the image yourself using the Dockerfile.