Skip to content

Commit

Permalink
Merge pull request #46 from RetroArcher/nightly
Browse files Browse the repository at this point in the history
v0.0.4
  • Loading branch information
ReenigneArcher authored Apr 25, 2022
2 parents 30f9dc4 + 2b0c7ac commit 5cb8935
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 32 deletions.
101 changes: 72 additions & 29 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,63 +36,106 @@ jobs:
needs: check_changelog

env:
TEST_TAG: ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:test
BASE_TAG: retroarcher/discord-bot

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Prepare
id: prepare
env:
NEXT_VERSION: ${{ needs.check_changelog.outputs.next_version }}
run: |
# determine to push image to dockerhub and ghcr or not
if [[ $GITHUB_EVENT_NAME == "push" ]]; then
PUSH=true
else
PUSH=false
fi
# setup the tags
TAGS="${BASE_TAG}:${GITHUB_SHA},ghcr.io/${BASE_TAG}:${GITHUB_SHA}"
if [[ $GITHUB_REF == refs/heads/master ]]; then
TAGS="${TAGS},${BASE_TAG}:latest,ghcr.io/${BASE_TAG}:latest"
TAGS="${TAGS},${BASE_TAG}:master,ghcr.io/${BASE_TAG}:master"
elif [[ $GITHUB_REF == refs/heads/nightly ]]; then
TAGS="${TAGS},${BASE_TAG}:nightly,ghcr.io/${BASE_TAG}:nightly"
else
TAGS="${TAGS},${BASE_TAG}:test,ghcr.io/${BASE_TAG}:test"
fi
if [[ ${NEXT_VERSION} != "" ]]; then
TAGS="${TAGS},${BASE_TAG}:${NEXT_VERSION},ghcr.io/${BASE_TAG}:${NEXT_VERSION}"
fi
echo ::set-output name=branch::${GITHUB_REF#refs/heads/}
echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=commit::${GITHUB_SHA}
echo ::set-output name=platforms::linux/386,linux/amd64,linux/arm64/v8
echo ::set-output name=push::${PUSH}
echo ::set-output name=tags::${TAGS}
- name: Set Up QEMU
uses: docker/setup-qemu-action@v1

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

- name: Cache Docker Layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Log in to Docker Hub
if: ${{ steps.prepare.outputs.push == 'true' }} # PRs do not have access to secrets
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Log in to the Container registry
if: ${{ steps.prepare.outputs.push == 'true' }} # PRs do not have access to secrets
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and export to Docker
- name: Build and push
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
load: true
tags: ${{ env.TEST_TAG }}
push: ${{ steps.prepare.outputs.push }}
platforms: ${{ steps.prepare.outputs.platforms }}
build-args: |
BRANCH=${{ steps.prepare.outputs.branch }}
COMMIT=${{ steps.prepare.outputs.commit }}
BUILD_DATE=${{ steps.prepare.outputs.build_date }}
tags: ${{ steps.prepare.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Test Image
run: |
docker run -d -e 'bot_token=${{ secrets.DISCORD_TEST_BOT_TOKEN }}' ${{ env.TEST_TAG }}
- name: Build and push (non master)
if: ${{ github.event_name == 'push' && github.ref != 'refs/heads/master' }}
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
push: true
tags: |
${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ github.ref_name }}
ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ github.ref_name }}
- name: Build and push (master)
- name: Update Docker Hub Description
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: docker/build-push-action@v2
uses: peter-evans/dockerhub-description@v3
with:
context: ./
file: ./Dockerfile
push: true
tags: |
${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:latest
ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:latest
${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ needs.check_changelog.outputs.next_version }}
ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ needs.check_changelog.outputs.next_version }}
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }} # token is not currently supported
repository: ${{ env.BASE_TAG }}
short-description: ${{ github.event.repository.description }}
readme-filepath: ./DOCKER_README.md

create_release:
runs-on: ubuntu-latest
needs: [check_changelog, docker]
steps:

- name: Create/Update GitHub Release
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.0.4] - 2022-04-24
### Fixed
- Corrected environment variable for daily release task

## [0.0.3] - 2022-04-06
### Fixed
- Environment variable names switched to uppercase
Expand Down
82 changes: 82 additions & 0 deletions DOCKER_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Docker

## Using docker run
Create and run the container (substitute your `<values>`):

```bash
docker run -d \
--name=retroarcher-discord-bot \
--restart=unless-stopped \
-e BOT_TOKEN=<BOT_TOKEN> \
-e DAILY_CHANNEL_ID=<DAILY_CHANNEL_ID> \
-e DAILY_RELEASES=<DAILY_RELEASES> \
-e DAILY_TASKS=<DAILY_TASKS> \
-e DAILY_TASKS_UTC_HOUR=<DAILY_TASKS_UTC_HOUR> \
-e GRAVATAR_EMAIL=<GRAVATAR_EMAIL> \
-e IGDB_CLIENT_ID=<IGDB_CLIENT_ID> \
-e IGDB_CLIENT_SECRET=<IGDB_CLIENT_SECRET> \
retroarcher/discord-bot
```

To update the container it must be removed and recreated:

```bash
# Stop the container
docker stop retroarcher-discord-bot
# Remove the container
docker rm retroarcher-discord-bot
# Pull the latest update
docker pull retroarcher/discord-bot
# Run the container with the same parameters as before
docker run -d ...
```

## Using docker-compose

Create a `docker-compose.yml` file with the following contents (substitute your `<values>`):

```yaml
version: '3'
services:
retroarcher-discord-bot:
image: retroarcher/discord-bot
container_name: retroarcher-discord-bot
restart: unless-stopped
environment:
- BOT_TOKEN=<BOT_TOKEN>
- DAILY_CHANNEL_ID=<DAILY_CHANNEL_ID>
- DAILY_RELEASES=<DAILY_RELEASES>
- DAILY_TASKS=<DAILY_TASKS>
- DAILY_TASKS_UTC_HOUR=<DAILY_TASKS_UTC_HOUR>
- GRAVATAR_EMAIL=<GRAVATAR_EMAIL>
- IGDB_CLIENT_ID=<IGDB_CLIENT_ID>
- IGDB_CLIENT_SECRET=<IGDB_CLIENT_SECRET>
```
Create and start the container (run the command from the same folder as your `docker-compose.yml` file):

```bash
docker-compose up -d
```

To update the container:
```bash
# Pull the latest update
docker-compose pull
# Update and restart the container
docker-compose up -d
```

## Parameters
You must substitute the `<values>` with your own settings.

| Parameter | Required | Default | Description |
| -------------------- | -------- | ------- | ------------------------------------------------------------- |
| BOT_TOKEN | True | None | Token from Bot page on discord developer portal. |
| DAILY_TASKS | False | true | Daily tasks on or off. |
| DAILY_RELEASES | False | true | Send a message for each game released on this day in history. |
| DAILY_CHANNEL_ID | False | None | Required if daily_tasks is enabled. |
| DAILY_TASKS_UTC_HOUR | False | 12 | The hour to run daily tasks. |
| GRAVATAR_EMAIL | False | None | Gravatar email address for bot avatar. |
| IGDB_CLIENT_ID | False | None | Required if daily_releases is enabled. |
| IGDB_CLIENT_SECRET | False | None | Required if daily_releases is enabled. |
2 changes: 1 addition & 1 deletion discord_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ async def daily_task():
except KeyError:
daily_releases = True
else:
if os.environ['DAILY_TASKS'].lower() == 'true':
if os.environ['DAILY_RELEASES'].lower() == 'true':
daily_releases = True
else:
print("'DAILY_RELEASES' environment variable is disabled")
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Flask==2.0.2
Flask==2.1.1
igdb-api-v4==0.0.5
libgravatar==1.0.0
py-cord==2.0.0b3
python-dotenv==0.19.2
python-dotenv==0.20.0
requests==2.27.1

0 comments on commit 5cb8935

Please sign in to comment.