|
FROM python:3.13-alpine |
|
|
|
LABEL authors="maurigamg" |
|
|
|
# 1. Update and upgrade Alpine packages |
|
RUN apk --no-cache update && \ |
|
apk --no-cache upgrade && \ |
|
rm -rf /var/cache/apk/* |
|
|
|
|
|
# 2. Install the GitHub CLI |
|
|
|
## Option 1: Download a precompiled binary and install it manually (Recommended) |
|
## In this case, we're downloading the latest release for linux_arm64 architecture because |
|
## the base image is for that architecture. |
|
RUN apk add --no-cache git curl jq \ |
|
&& curl -L \ |
|
-H "Accept: application/vnd.github+json" \ |
|
-H "X-GitHub-Api-Version: 2022-11-28" \ |
|
https://api.github.com/repos/cli/cli/releases/latest \ |
|
| jq -r '.assets[] | select(.name | endswith("linux_arm64.tar.gz")) | .browser_download_url' \ |
|
| xargs curl -L -o /tmp/gh.tar.gz \ |
|
&& tar -xzf /tmp/gh.tar.gz -C /tmp/ \ |
|
&& mv /tmp/gh_*/bin/gh /usr/local/bin/gh \ |
|
&& rm -rf /tmp \ |
|
&& apk del curl jq |
|
|
|
## Notes: If you need a specific version, replace the above RUN command with steps like these: |
|
# ARG GH_CLI_VERSION=2.83.1 |
|
# RUN apk add --no-cache git curl \ |
|
# && curl -L -o /tmp/gh.tar.gz \ |
|
# "https://github.com/cli/cli/releases/download/v${GH_CLI_VERSION}/gh_${GH_CLI_VERSION}_linux_arm64.tar.gz" \ |
|
# && tar -xzf /tmp/gh.tar.gz -C /tmp/ \ |
|
# && mv "/tmp/gh_${GH_CLI_VERSION}_linux_arm64/bin/gh" /usr/local/bin/gh \ |
|
# && rm -rf /tmp \ |
|
# && apk del curl |
|
|
|
## Option 2: Install via Alpine Linux community (Unofficial) |
|
# See https://github.com/cli/cli/blob/trunk/docs/install_linux.md#alpine-linux |
|
|
|
# 3. Authenticate GitHub CLI using a token |
|
|
|
## Option 1: Setting GH_TOKEN environment variable (see docker-compose.yaml) |
|
|
|
## Option 2: Using a token file |
|
#COPY token.txt /tmp/token.txt |
|
#RUN gh auth login --with-token < /tmp/token.txt && rm /tmp/token.txt |
|
|
|
## Option 3: Using build argument |
|
#ARG TOKEN |
|
#RUN gh auth login --with-token < <(printf "%s" "${TOKEN}") |
|
|
|
# 4. Setup SSH for Git operations |
|
|
|
# 4.1 Configure GitHub CLI to use SSH for git operations |
|
RUN gh config set git_protocol ssh -h github.com |
|
|
|
## 4.2 Install openssh-client |
|
RUN apk add --no-cache openssh-client |
|
|
|
## 4.3 Create known_hosts file to avoid SSH authenticity prompt since we cannot interactively accept it |
|
|
|
### Option 1: Using ssh-keyscan, which is simpler and already comes with openssh-client |
|
RUN mkdir -p /root/.ssh && ssh-keyscan github.com > /root/.ssh/known_hosts |
|
|
|
### Option 2: Using GitHub API to get SSH keys (more complex) |
|
# RUN apk add --no-cache curl jq \ |
|
# && mkdir -p /root/.ssh \ |
|
# && curl -L \ |
|
# -H "Accept: application/vnd.github+json" \ |
|
# -H "X-GitHub-Api-Version: 2022-11-28" \ |
|
# https://api.github.com/meta \ |
|
# | jq -r '.ssh_keys[] | "github.com \(.)"' \ |
|
# > /root/.ssh/known_hosts \ |
|
# && apk del curl jq |
|
|
|
### Option 3: Creating a static known_hosts file with hardcoded keys (see https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints) |
|
# RUN mkdir -p /root/.ssh && cat <<EOF > /root/.ssh/known_hosts |
|
# github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl |
|
# github.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg= |
|
# github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk= |
|
# EOF |
|
|
|
WORKDIR /app |
|
|
|
COPY main.py main.py |
|
COPY requirements.txt requirements.txt |
|
|
|
RUN pip install --no-cache-dir --upgrade pip \ |
|
&& pip install --no-cache-dir -r requirements.txt \ |
|
&& rm -rf .cache/pip \ |
|
&& rm requirements.txt |
|
|
|
ENTRYPOINT ["python", "main.py"] |