diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..5f6d2130 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,31 @@ +image: docker:latest +services: + - docker:dind + +before_script: + - apk add --no-cache python3 + - pip3 install pylint requests discord.py docker pybooru pylint wolframalpha + +stages: + - test + - deploy + +linting_python: + stage: test + script: + - pylint -E app/*.py + only: + - /.*/ + tags: + - docker + +build_and_push_container: + stage: deploy + script: + - docker login -u ldooks -p $DOCKER_PASSWORD + - docker build -t ldooks/dragon-bot:latest . + - docker push ldooks/dragon-bot:latest + only: + - master + tags: + - docker \ No newline at end of file diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml deleted file mode 100644 index 82c6fb47..00000000 --- a/bitbucket-pipelines.yml +++ /dev/null @@ -1,32 +0,0 @@ -# This is a sample build configuration for Docker. -# Check our guides at https://confluence.atlassian.com/x/O1toN for more examples. -# Only use spaces to indent your .yml configuration. -# ----- -# You can specify a custom docker image from Docker Hub as your build environment. -# image: atlassian/default-image:latest - -# enable Docker for your repository -options: - docker: true - -image: python:3.6.2 -pipelines: - default: - - step: - script: - - echo "Making sure the python actually runs" - - pip install docker discord.py pybooru requests pylint - - python dragon-bot.py test - - export IMAGE_NAME=ldooks/dragon-bot:latest - # build the Docker image (this will use the Dockerfile in the root of the repo) - - docker build -t $IMAGE_NAME . - branches: - master: - - step: - script: - - export IMAGE_NAME=ldooks/dragon-bot:latest - - docker build -t $IMAGE_NAME . - # authenticate with the Docker Hub registry - - docker login --username $DOCKER_HUB_USERNAME --password $DOCKER_HUB_PASSWORD - # push the new Docker image to the Docker registry - - docker push $IMAGE_NAME \ No newline at end of file diff --git a/test-dragon-bot.sh b/test-dragon-bot.sh index 1867bc89..c26395ec 100755 --- a/test-dragon-bot.sh +++ b/test-dragon-bot.sh @@ -1,3 +1,25 @@ +# Add the git hooks to the local repo. This prevents pushes on master +SCRIPTDIR="$(dirname "$0")" +HOOKDIR="$SCRIPTDIR/.git/hooks" +SCRIPT="$HOOKDIR/pre-push" +cat << EOF > $SCRIPT +#!/bin/bash +protected_branch='master' +# check each branch being pushed +while read local_ref local_sha remote_ref remote_sha +do + remote_branch=$(echo $remote_ref | sed -e 's,.*/\(.*\),\1,') + if [ $protected_branch = $remote_branch ] + then + echo "ABORT PUSH: Not allowed to push directly to $protected_branch. Use --no-verify to force." + exit 1 # push will not execute + fi +done +exit 0 +EOF + +chmod +x $SCRIPT + # Remove the running container so we cna re-use the container name 'dragon-bot' printf "\n[-] Deleting old dragon-bot container from system\n" docker rm -f dragon-bot-test