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

🐳 Multistage build #24

Merged
merged 8 commits into from
Apr 13, 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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = false
insert_final_newline = true
max_line_length = 120
tab_width = 4
trim_trailing_whitespace = true
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ jobs:
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64,linux/arm/v7


release:
runs-on: ubuntu-latest
if: ${{ needs.lint.outputs.is_release }}
Expand Down Expand Up @@ -141,7 +140,6 @@ jobs:

- name: Release
uses: softprops/action-gh-release@v1

with:
body: |
Docker image: [`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.version }}`](https://github.com/jag-k/owntinfoil/pkgs/container/owntinfoil/${{ steps.docker_build.outputs }}?tag=${{ steps.get_version.outputs.version }})
Expand Down
60 changes: 55 additions & 5 deletions .github/workflows/pr_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:

jobs:
validate-pr:
validate-labels:
runs-on: ubuntu-latest
steps:
- name: Check labels
Expand All @@ -13,7 +13,9 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const { data: pullRequest } = await github.rest.pulls.get({
const {
data: pullRequest
} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
Expand All @@ -37,7 +39,9 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const { data: pullRequest } = await github.rest.pulls.get({
const {
data: pullRequest
} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
Expand All @@ -53,7 +57,9 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const { data: pullRequest } = await github.rest.pulls.get({
const {
data: pullRequest
} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
Expand Down Expand Up @@ -96,7 +102,6 @@ jobs:
runs-on: ubuntu-latest
needs:
- validate-code

if: startsWith(github.head_ref, 'release/')
steps:
- name: Check branch name with version
Expand All @@ -109,3 +114,48 @@ jobs:
echo "Branch name does not match the version in pyproject.toml"
exit 1
fi

validate-docker-build:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
packages: read
strategy:
matrix:
platform: [linux/amd64, linux/arm64, linux/arm/v7]
steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
labels: |
org.opencontainers.image.revision=${{ github.sha }}
tags: |
type=sha,prefix=,suffix=,format=short

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.platform }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.platform }}-

- name: Build Docker image for ${{ matrix.platform }}
uses: docker/build-push-action@v5
id: build-and-push
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
platforms: ${{ matrix.platform }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12-slim as base
FROM --platform=$BUILDPLATFORM python:3.12-slim as base

LABEL org.opencontainers.image.source="https://github.com/jag-k/owntinfoil"
LABEL org.opencontainers.image.description="OwnTinfoil Image"
Expand Down
2 changes: 1 addition & 1 deletion app/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def get_data(self, retries: int = 2) -> bytes:
print(f"Server disconnected for file {self.name!r}, retrying...", file=sys.stderr)
retries -= 1
print(f"Failed to download file {self.name!r} after {original_retries} retries!", file=sys.stderr)
return None
return b""

@staticmethod
def normalize_name(name: str) -> str:
Expand Down