Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Dockerfile #81

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

feat: Add Dockerfile #81

wants to merge 8 commits into from

Conversation

Karina5005
Copy link
Member

@Karina5005 Karina5005 commented Oct 16, 2023

Fixes: #77

Dockerfile Outdated
RUN mkdir "/backup/backup"
RUN mkdir "/backup/metrics"

RUN pip install backup-github-org==1.0.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not hardcode version here. Use ARG instead:

ARG VERSION
RUN pip install backup-github-org==${VERSION}

Dockerfile Outdated
WORKDIR /backup

ENV ACCESS_TOKEN=""
ENV ORGANIZATION=""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think about approach: image should contain only application, not environment. In other words image shouldn't contain any environments.
Your env variables are part of environment.

Dockerfile Outdated
apt-get install -y git

RUN mkdir "/backup/backup"
RUN mkdir "/backup/metrics"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put all RUN into one

Dockerfile Outdated

RUN pip install backup-github-org==1.0.4

ENTRYPOINT backup-github --all -t $ACCESS_TOKEN -o /backup/backup --metrics_path /backup/metrics/${ORGANIZATION}.prom $ORGANIZATION
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In short: do not use entrypoint, use cmd. If you want to know more, google it - 'entrypoint vs cmd'.

If speak roughly - you don't need to care about how to run application inside container, you only need to pack it into image

Dockerfile Outdated
ENV ACCESS_TOKEN=""
ENV ORGANIZATION=""

RUN apt-get update && apt-get upgrade -y && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up apt cache at the end of dockerfile

Dockerfile Outdated
ENV ACCESS_TOKEN=""
ENV ORGANIZATION=""

RUN apt-get update && apt-get upgrade -y && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use upgrade, it's antipattern

Dockerfile Outdated
ENV ORGANIZATION=""

RUN apt-get update && apt-get upgrade -y && \
apt-get install -y git
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need git here?

Dockerfile Outdated

ENTRYPOINT backup-github --all -t $ACCESS_TOKEN -o /backup/backup --metrics_path /backup/metrics/${ORGANIZATION}.prom $ORGANIZATION

# Run command: docker run -rm -v .\backup:/backup/backup -v .\metrics:/backup/metrics -e ACCESS_TOKEN={} -e ORGANIZATION={}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally your Dockerfile should look like this:

FROM python:3.10
WORKDIR /backup

ARG VERSION
ENV DEBIAN_FRONTEND=noninteractive
RUN mkdir /backup/{backup,metrics} \
    && pip install backup-github-org==${VERSION}

CMD ["backup-github", "--help"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker container
2 participants