Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Push image to Dockerhub #5

Merged
merged 8 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 43 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,10 @@ jobs:
build_docker_multi_arch:
needs: create_infrastructure
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- name: checkout
uses: actions/checkout@v4

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::246770851643:role/github-actions
aws-region: us-east-1

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
Expand All @@ -104,6 +97,18 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::246770851643:role/github-actions
aws-region: us-east-1

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
Expand All @@ -129,9 +134,25 @@ jobs:
- name: export requirements
run: poetry export -f requirements.txt -o requirements.txt --without-hashes

- name: Docker meta
id: meta-dockerhub
uses: docker/metadata-action@v5
with:
images: tobiaswaslowski/mood-tracker
flavor: |
latest=true
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha

- name: Docker meta
id: meta
id: meta-ecr
uses: docker/metadata-action@v5
with:
images: public.ecr.aws/c1o1h8f4/mood-tracker
Expand All @@ -147,13 +168,25 @@ jobs:
type=semver,pattern={{major}}
type=sha


- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta-dockerhub.outputs.tags }}
labels: ${{ steps.meta-dockerhub.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta-ecr.outputs.tags }}
labels: ${{ steps.meta-ecr.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Assuming you have a MongoDB instance running on your local machine that is bound
(e.g. by running `docker run -p 27017:27017 mongo`) you can run the following command:

docker run --env TELEGRAM_TOKEN=$TELEGRAM_TOKEN \
public.ecr.aws/c1o1h8f4/mood-tracker:latest
tobiaswaslowski/mood-tracker:latest

Supported architectures are x86_64 (amd64) and arm64. If you require images
for additional architectures, feel free to raise a ticket or build your own images (see [Development](#development)).
Expand Down Expand Up @@ -97,7 +97,7 @@ The run command in that case could look like this:
docker run --env TELEGRAM_TOKEN=$TELEGRAM_TOKEN \
--env MONGO_HOST=192.168.1.1:27017 \
--network="host" \
public.ecr.aws/c1o1h8f4/mood-tracker:latest
tobiaswaslowski/mood-tracker:latest

For more guidance on Docker networking, please refer to the [official documentation](https://docs.docker.com/network/).

Expand All @@ -116,7 +116,7 @@ docker run -d --rm \
--name mood-tracker \
-e TELEGRAM_TOKEN="$TELEGRAM_TOKEN" \
-v "$HOME/.aws/credentials:/root/.aws/credentials:ro" \
public.ecr.aws/c1o1h8f4/mood-tracker:latest
tobiaswaslowski/mood-tracker:latest
```

Why `/root/.aws/credentials`? Because `boto3` checks in the home directory of the user running the script for the
Expand All @@ -134,7 +134,7 @@ docker run -d --rm \
--name mood-tracker \
-e TELEGRAM_TOKEN="$TELEGRAM_TOKEN" \
-v ./config.yaml:/app/config.yaml \
public.ecr.aws/c1o1h8f4/mood-tracker:latest
tobiaswaslowski/mood-tracker:latest
```

# Configuration
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- mongo_data:/data/db

mood-tracker:
image: public.ecr.aws/c1o1h8f4/mood-tracker:latest
image: tobiaswaslowski/mood-tracker:latest
build:
context: .
dockerfile: Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ sudo docker run -d --rm \
--security-opt seccomp:unconfined \
-v "$HOME/.aws/credentials:/root/.aws/credentials:ro" \
-v ./config.yaml:/app/config.yaml \
public.ecr.aws/c1o1h8f4/mood-tracker:latest
tobiaswaslowski/mood-tracker:latest
27 changes: 9 additions & 18 deletions terraform/files/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
# Usage

## DEPRECATION NOTICE

I'm discontinuing support for ECR. Please use the Docker Hub image instead. The new repository is:

tobiaswaslowski/mood-tracker

## Quickstart

I host the Docker image for this application on a public ECR repository. You have to create your own
Telegram via the [Botfather](https://t.me/botfather) and supply it to the container as an environment variable.
You have to create your ownm Telegram via the [Botfather](https://t.me/botfather) and supply it to the container as an environment variable.
Additionally, you'll have to have a MongoDB instance running for persistence.
Assuming you have a MongoDB instance running on your local machine that is bound to `127.0.0.1:27017`,
(e.g. by running `docker run -p 27017:27017 mongo`) you can run the following command:

docker run --env TELEGRAM_TOKEN=$TELEGRAM_TOKEN \
public.ecr.aws/c1o1h8f4/mood-tracker:latest

Supported architectures are x86_64 (amd64) and arm64. If you require images
for additional architectures, feel free to raise a ticket or build your own images (see [Development](#development)).

## MongoDB Configuration

If your MongoDB instance is bound to a different hosts, you'll have to supply the connection string as an environment
variable. If you're running Docker for Linux, I recommend using `--network="host"` for simplicity's sake.
The run command in that case could look like this:

docker run --env TELEGRAM_TOKEN=$TELEGRAM_TOKEN \
--env MONGO_HOST=192.168.1.1:27017 \
--network="host" \
public.ecr.aws/c1o1h8f4/mood-tracker:latest
tobiaswaslowski/mood-tracker:latest

For more guidance on Docker networking, please refer to the [official documentation](https://docs.docker.com/network/).
DynamoDB is also supported as a backend. For more information, check out the [documentation](https://github.com/twaslowski/telegram-mood-tracker?tab=readme-ov-file#running).