Skip to content

Commit 5cb8935

Browse files
Merge pull request #46 from RetroArcher/nightly
v0.0.4
2 parents 30f9dc4 + 2b0c7ac commit 5cb8935

File tree

5 files changed

+161
-32
lines changed

5 files changed

+161
-32
lines changed

.github/workflows/CI.yml

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,63 +36,106 @@ jobs:
3636
needs: check_changelog
3737

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

4141
steps:
4242
- name: Checkout
4343
uses: actions/checkout@v3
4444

45+
- name: Prepare
46+
id: prepare
47+
env:
48+
NEXT_VERSION: ${{ needs.check_changelog.outputs.next_version }}
49+
run: |
50+
# determine to push image to dockerhub and ghcr or not
51+
if [[ $GITHUB_EVENT_NAME == "push" ]]; then
52+
PUSH=true
53+
else
54+
PUSH=false
55+
fi
56+
57+
# setup the tags
58+
TAGS="${BASE_TAG}:${GITHUB_SHA},ghcr.io/${BASE_TAG}:${GITHUB_SHA}"
59+
60+
if [[ $GITHUB_REF == refs/heads/master ]]; then
61+
TAGS="${TAGS},${BASE_TAG}:latest,ghcr.io/${BASE_TAG}:latest"
62+
TAGS="${TAGS},${BASE_TAG}:master,ghcr.io/${BASE_TAG}:master"
63+
elif [[ $GITHUB_REF == refs/heads/nightly ]]; then
64+
TAGS="${TAGS},${BASE_TAG}:nightly,ghcr.io/${BASE_TAG}:nightly"
65+
else
66+
TAGS="${TAGS},${BASE_TAG}:test,ghcr.io/${BASE_TAG}:test"
67+
fi
68+
69+
if [[ ${NEXT_VERSION} != "" ]]; then
70+
TAGS="${TAGS},${BASE_TAG}:${NEXT_VERSION},ghcr.io/${BASE_TAG}:${NEXT_VERSION}"
71+
fi
72+
73+
echo ::set-output name=branch::${GITHUB_REF#refs/heads/}
74+
echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
75+
echo ::set-output name=commit::${GITHUB_SHA}
76+
echo ::set-output name=platforms::linux/386,linux/amd64,linux/arm64/v8
77+
echo ::set-output name=push::${PUSH}
78+
echo ::set-output name=tags::${TAGS}
79+
80+
- name: Set Up QEMU
81+
uses: docker/setup-qemu-action@v1
82+
4583
- name: Set up Docker Buildx
4684
uses: docker/setup-buildx-action@v1
85+
id: buildx
86+
87+
- name: Cache Docker Layers
88+
uses: actions/cache@v3
89+
with:
90+
path: /tmp/.buildx-cache
91+
key: ${{ runner.os }}-buildx-${{ github.sha }}
92+
restore-keys: |
93+
${{ runner.os }}-buildx-
4794
4895
- name: Log in to Docker Hub
96+
if: ${{ steps.prepare.outputs.push == 'true' }} # PRs do not have access to secrets
4997
uses: docker/login-action@v1
5098
with:
5199
username: ${{ secrets.DOCKER_HUB_USERNAME }}
52100
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
53101

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

61-
- name: Build and export to Docker
110+
- name: Build and push
62111
uses: docker/build-push-action@v2
63112
with:
64113
context: ./
65114
file: ./Dockerfile
66-
load: true
67-
tags: ${{ env.TEST_TAG }}
115+
push: ${{ steps.prepare.outputs.push }}
116+
platforms: ${{ steps.prepare.outputs.platforms }}
117+
build-args: |
118+
BRANCH=${{ steps.prepare.outputs.branch }}
119+
COMMIT=${{ steps.prepare.outputs.commit }}
120+
BUILD_DATE=${{ steps.prepare.outputs.build_date }}
121+
tags: ${{ steps.prepare.outputs.tags }}
122+
cache-from: type=local,src=/tmp/.buildx-cache
123+
cache-to: type=local,dest=/tmp/.buildx-cache
68124

69-
- name: Test Image
70-
run: |
71-
docker run -d -e 'bot_token=${{ secrets.DISCORD_TEST_BOT_TOKEN }}' ${{ env.TEST_TAG }}
72-
73-
- name: Build and push (non master)
74-
if: ${{ github.event_name == 'push' && github.ref != 'refs/heads/master' }}
75-
uses: docker/build-push-action@v2
76-
with:
77-
context: ./
78-
file: ./Dockerfile
79-
push: true
80-
tags: |
81-
${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ github.ref_name }}
82-
ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ github.ref_name }}
83-
84-
- name: Build and push (master)
125+
- name: Update Docker Hub Description
85126
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
86-
uses: docker/build-push-action@v2
127+
uses: peter-evans/dockerhub-description@v3
87128
with:
88-
context: ./
89-
file: ./Dockerfile
90-
push: true
91-
tags: |
92-
${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:latest
93-
ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:latest
94-
${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ needs.check_changelog.outputs.next_version }}
95-
ghcr.io/${{ secrets.DOCKER_HUB_USERNAME }}/discord-bot:${{ needs.check_changelog.outputs.next_version }}
129+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
130+
password: ${{ secrets.DOCKER_HUB_PASSWORD }} # token is not currently supported
131+
repository: ${{ env.BASE_TAG }}
132+
short-description: ${{ github.event.repository.description }}
133+
readme-filepath: ./DOCKER_README.md
134+
135+
create_release:
136+
runs-on: ubuntu-latest
137+
needs: [check_changelog, docker]
138+
steps:
96139

97140
- name: Create/Update GitHub Release
98141
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [0.0.4] - 2022-04-24
4+
### Fixed
5+
- Corrected environment variable for daily release task
6+
37
## [0.0.3] - 2022-04-06
48
### Fixed
59
- Environment variable names switched to uppercase

DOCKER_README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Docker
2+
3+
## Using docker run
4+
Create and run the container (substitute your `<values>`):
5+
6+
```bash
7+
docker run -d \
8+
--name=retroarcher-discord-bot \
9+
--restart=unless-stopped \
10+
-e BOT_TOKEN=<BOT_TOKEN> \
11+
-e DAILY_CHANNEL_ID=<DAILY_CHANNEL_ID> \
12+
-e DAILY_RELEASES=<DAILY_RELEASES> \
13+
-e DAILY_TASKS=<DAILY_TASKS> \
14+
-e DAILY_TASKS_UTC_HOUR=<DAILY_TASKS_UTC_HOUR> \
15+
-e GRAVATAR_EMAIL=<GRAVATAR_EMAIL> \
16+
-e IGDB_CLIENT_ID=<IGDB_CLIENT_ID> \
17+
-e IGDB_CLIENT_SECRET=<IGDB_CLIENT_SECRET> \
18+
retroarcher/discord-bot
19+
```
20+
21+
To update the container it must be removed and recreated:
22+
23+
```bash
24+
# Stop the container
25+
docker stop retroarcher-discord-bot
26+
# Remove the container
27+
docker rm retroarcher-discord-bot
28+
# Pull the latest update
29+
docker pull retroarcher/discord-bot
30+
# Run the container with the same parameters as before
31+
docker run -d ...
32+
```
33+
34+
## Using docker-compose
35+
36+
Create a `docker-compose.yml` file with the following contents (substitute your `<values>`):
37+
38+
```yaml
39+
version: '3'
40+
services:
41+
retroarcher-discord-bot:
42+
image: retroarcher/discord-bot
43+
container_name: retroarcher-discord-bot
44+
restart: unless-stopped
45+
environment:
46+
- BOT_TOKEN=<BOT_TOKEN>
47+
- DAILY_CHANNEL_ID=<DAILY_CHANNEL_ID>
48+
- DAILY_RELEASES=<DAILY_RELEASES>
49+
- DAILY_TASKS=<DAILY_TASKS>
50+
- DAILY_TASKS_UTC_HOUR=<DAILY_TASKS_UTC_HOUR>
51+
- GRAVATAR_EMAIL=<GRAVATAR_EMAIL>
52+
- IGDB_CLIENT_ID=<IGDB_CLIENT_ID>
53+
- IGDB_CLIENT_SECRET=<IGDB_CLIENT_SECRET>
54+
```
55+
56+
Create and start the container (run the command from the same folder as your `docker-compose.yml` file):
57+
58+
```bash
59+
docker-compose up -d
60+
```
61+
62+
To update the container:
63+
```bash
64+
# Pull the latest update
65+
docker-compose pull
66+
# Update and restart the container
67+
docker-compose up -d
68+
```
69+
70+
## Parameters
71+
You must substitute the `<values>` with your own settings.
72+
73+
| Parameter | Required | Default | Description |
74+
| -------------------- | -------- | ------- | ------------------------------------------------------------- |
75+
| BOT_TOKEN | True | None | Token from Bot page on discord developer portal. |
76+
| DAILY_TASKS | False | true | Daily tasks on or off. |
77+
| DAILY_RELEASES | False | true | Send a message for each game released on this day in history. |
78+
| DAILY_CHANNEL_ID | False | None | Required if daily_tasks is enabled. |
79+
| DAILY_TASKS_UTC_HOUR | False | 12 | The hour to run daily tasks. |
80+
| GRAVATAR_EMAIL | False | None | Gravatar email address for bot avatar. |
81+
| IGDB_CLIENT_ID | False | None | Required if daily_releases is enabled. |
82+
| IGDB_CLIENT_SECRET | False | None | Required if daily_releases is enabled. |

discord_bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ async def daily_task():
382382
except KeyError:
383383
daily_releases = True
384384
else:
385-
if os.environ['DAILY_TASKS'].lower() == 'true':
385+
if os.environ['DAILY_RELEASES'].lower() == 'true':
386386
daily_releases = True
387387
else:
388388
print("'DAILY_RELEASES' environment variable is disabled")

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Flask==2.0.2
1+
Flask==2.1.1
22
igdb-api-v4==0.0.5
33
libgravatar==1.0.0
44
py-cord==2.0.0b3
5-
python-dotenv==0.19.2
5+
python-dotenv==0.20.0
66
requests==2.27.1

0 commit comments

Comments
 (0)