Skip to content

Commit

Permalink
Add env-flutter
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Oct 16, 2024
1 parent 8ff15d8 commit f2016a0
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 172 deletions.
105 changes: 88 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ concurrency:
cancel-in-progress: true

jobs:
images:
linux-images:
runs-on: ubuntu-latest

strategy:
Expand All @@ -31,6 +31,8 @@ jobs:
- env-archlinux
- env-debian
- env-fedora
- env-flutter:android
- env-flutter:linux
- env-opensuse
- env-sphinx
- env-ubuntu:14.04
Expand All @@ -47,29 +49,27 @@ jobs:
- toolchain-mips-openwrt-linux-atheros
- toolchain-linux-android

name: ${{ matrix.image }}
name: linux/${{ matrix.image }}

env:
CACHE_FROM: /tmp/.buildx-cache
CACHE_TO: /tmp/.buildx-cache-new
CACHE_FROM: /tmp/dockercache
CACHE_TO: /tmp/dockercache-new

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup cache
uses: actions/cache@v4
- name: Restore cache
uses: actions/cache/restore@v4
with:
path: ${{ env.CACHE_FROM }}
key: ${{ matrix.image }}-${{ github.sha }}
restore-keys: |
${{ matrix.image }}-
key: ${{ runner.os }}-${{ matrix.image }}

- name: Setup buildx
run: |
docker buildx create --use
- name: Setup env
- name: Detect env
if: |
github.repository_owner == 'roc-streaming' &&
github.event_name == 'push' &&
Expand All @@ -79,22 +79,93 @@ jobs:
- name: Run docker
run: |
set -x
if [[ $ENABLE_PUSH = 1 ]]; then \
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
./make.sh --push ${{ matrix.image }}
./make.py --push \
--cache-from=${{ env.CACHE_FROM }} --cache-to=${{ env.CACHE_TO }} \
${{ matrix.image }}
else
./make.sh ${{ matrix.image }}
./make.py \
--cache-from=${{ env.CACHE_FROM }} --cache-to=${{ env.CACHE_TO }} \
${{ matrix.image }}
fi
- name: Move cache
- name: Save cache
uses: actions/cache/save@v4
if: always()
with:
path: ${{ env.CACHE_TO }}
key: ${{ runner.os }}-${{ matrix.image }}-${{ github.sha }}

windows-images:
runs-on: windows-latest

strategy:
fail-fast: false
matrix:
image:
- env-flutter

name: windows/${{ matrix.image }}

env:
CACHE_DIR: C:\dockercache

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Restore cache
uses: actions/cache/restore@v4
with:
path: ${{ env.CACHE_DIR }}
key: ${{ runner.os }}-${{ matrix.image }}

- name: Load images
run: |
Set-PSDebug -Trace 1
if (Test-Path -Path ${{ env.CACHE_DIR }}\rocstreaming) {
Get-ChildItem -Path ${{ env.CACHE_DIR }}\rocstreaming -Filter *.tar | ForEach-Object {
docker load -i $_.FullName
Remove-Item $_.FullName
}
}
- name: Detect env
if: |
github.repository_owner == 'roc-streaming' &&
github.event_name == 'push' &&
github.ref == 'refs/heads/main'
run: |
echo "ENABLE_PUSH=1" >> $env:GITHUB_ENV
- name: Run docker
run: |
Set-PSDebug -Trace 1
if ($env:ENABLE_PUSH -eq "1") {
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
python make.py --push ${{ matrix.image }}
} else {
python make.py ${{ matrix.image }}
}
- name: Save images
if: always()
run: |
rm -rf ${CACHE_FROM}
mv ${CACHE_TO} ${CACHE_FROM}
Set-PSDebug -Trace 1
New-Item -ItemType Directory -Path ${{ env.CACHE_DIR }}\rocstreaming -Force `
-ErrorAction SilentlyContinue
docker images --format '{{.Repository}}:{{.Tag}}' `
| Select-String -Pattern "^rocstreaming/${{ matrix.image }}(:|$)" | ForEach-Object {
$image = $_.ToString()
$file = $image -Replace ":", "-"
docker save $image -o "${{ env.CACHE_DIR }}\$file.tar"
}
- name: Save cache
uses: actions/cache/save@v4
if: always()
with:
path: ${{ env.CACHE_FROM }}
key: ${{ matrix.image }}-${{ github.sha }}
path: ${{ env.CACHE_DIR }}
key: ${{ runner.os }}-${{ matrix.image }}-${{ github.sha }}
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ Documentation for this process is [available here](https://roc-streaming.org/too
To build image(s) locally, run:

```
./make.sh [OPTIONS...] IMAGE[:TAG]...
./make.py [OPTIONS...] IMAGE[:TAG]...
```

For example (build all tags of `env-ubuntu`):

```
./make.sh env-ubuntu
./make.py env-ubuntu
```

Or (build all tags of `env-fedora` and two specific tags of `env-ubuntu`):

```
./make.sh env-fedora env-ubuntu:20.04 env-ubuntu:22.04
./make.py env-fedora env-ubuntu:20.04 env-ubuntu:22.04
```

To build all images, run:

```
./make.sh [OPTIONS...]
./make.py [OPTIONS...]
```

Use `-n` flag to see what's going to happen without actually doing anything, for example:

```
./make.sh -n
./make.py -n
```

For the full list of available options, run:

```
./make.sh --help
./make.py --help
```
22 changes: 22 additions & 0 deletions images/env-flutter/Dockerfile.android
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM ghcr.io/cirruslabs/flutter:stable

USER root
ENV HOME=/root
ENV ANDROID_USER_HOME=/root/.android
ENV GRADLE_USER_HOME=/root/.gradle

RUN git config --global --add safe.directory /sdks/flutter && \
flutter --disable-analytics && \
flutter config --no-cli-animations

RUN mkdir -p /root/.android && \
yes | keytool -genkey -v -keystore /root/.android/debug.keystore \
-alias androiddebugkey -storepass android -keypass android \
-keyalg RSA -validity 14000

RUN find /sdks -type d -exec chmod a+rwx '{}' ';' && \
find /sdks -type f -exec chmod a+rw '{}' ';' && \
find /opt -type d -exec chmod a+rwx '{}' ';' && \
find /opt -type f -exec chmod a+rw '{}' ';' && \
find /root -type d -exec chmod a+rwx '{}' ';' && \
find /root -type f -exec chmod a+rw '{}' ';'
15 changes: 15 additions & 0 deletions images/env-flutter/Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM openpriv/flutter-desktop:linux-fstable-3.22.2

USER root
ENV HOME=/root

RUN git config --global --add safe.directory /sdks/flutter && \
flutter --disable-analytics && \
flutter config --no-cli-animations

RUN find /sdks -type d -exec chmod a+rwx '{}' ';' && \
find /sdks -type f -exec chmod a+rw '{}' ';' && \
find /opt -type d -exec chmod a+rwx '{}' ';' && \
find /opt -type f -exec chmod a+rw '{}' ';' && \
find /root -type d -exec chmod a+rwx '{}' ';' && \
find /root -type f -exec chmod a+rw '{}' ';'
1 change: 1 addition & 0 deletions images/env-flutter/Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM openpriv/flutter-desktop:windows-sdk30-fstable-3.22.2
4 changes: 4 additions & 0 deletions images/env-flutter/images.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DOCKERFILE;ARGS (comma-separated list);TAG;OS
Dockerfile.android;;android;linux
Dockerfile.linux;;linux;linux
Dockerfile.windows;;windows;windows
3 changes: 2 additions & 1 deletion images/env-sphinx/requirements.unversioned.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Requirements file used to install latest, which we then freeze.
Sphinx
breathe
mkdocs
Sphinx
sphinxemoji
122 changes: 122 additions & 0 deletions make.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/usr/bin/env python3

import argparse
import os
import os.path
import platform
import subprocess
import sys

DRY_RUN = False

def print_msg(msg):
if platform.system() != 'Windows':
print(f'-- \033[1;35m{msg}\033[0m', file=sys.stderr)
else:
print(msg, file=sys.stderr)

def print_cmd(cmd):
if not isinstance(cmd, (list, tuple)):
cmd = [cmd]
print(f"-- {' '.join(cmd)}", file=sys.stderr)

def run_cmd(*args):
print_cmd(args)
if not DRY_RUN:
subprocess.check_call(args)

parser = argparse.ArgumentParser()
parser.add_argument('-n', '--dry-run', action='store_true', help="don't run commands, just print them")
parser.add_argument('-p', '--push', action='store_true', help="push image after building")
parser.add_argument('-C', '--no-cache', action='store_true', help="pass --no-cache to docker build")
parser.add_argument('-P', '--no-pull', action='store_true', help="don't pass --pull to docker build")
parser.add_argument('--cache-from', type=str, help="from where to load buildx cache")
parser.add_argument('--cache-to', type=str, help="to where to save buildx cache")
parser.add_argument('image', nargs='*', default=None)

args = parser.parse_args()

DRY_RUN = args.dry_run

os.chdir(os.path.dirname(__file__))

if args.image:
images = args.image
else:
images = sorted(os.listdir('images'))

for image in images:
if ':' in image:
image_shortname, image_tag = image.split(':')
else:
image_shortname = image
image_tag = ''

image_fullname = f'rocstreaming/{image_shortname}'
image_dir = f'images/{image_shortname}'

os.chdir(image_dir)

with open('images.csv') as fp:
for n, line in enumerate(fp.readlines()):
if n == 0:
continue
parts = line.strip().split(';')
if len(parts) == 4:
dockerfile, build_args, tag, osname = parts
else:
dockerfile, build_args, tag = parts
osname = 'linux'

if not dockerfile:
dockerfile = 'Dockerfile'
if not tag:
tag = dockerfile.split('/')[0]

if '/' in dockerfile:
context = dockerfile.split('/')[0]
else:
context = '.'

if image_tag and tag != image_tag:
continue
if osname != platform.system().lower():
continue

print_msg(f'processing image {image_fullname}:{tag}')
print_cmd(f'cd {image_dir}')

if platform.system() != 'Windows':
docker_args = ['buildx', 'build', '--output', 'type=docker']
else:
docker_args = ['build']

if not args.no_pull:
docker_args += ['--pull']
if args.no_cache:
docker_args += ['--no-cache']
else:
if args.cache_from and os.path.exists(os.path.join(args.cache_from, 'index.json')):
docker_args += ['--cache-from', f'type=local,src={args.cache_from}']
if args.cache_to:
if not DRY_RUN:
os.makedirs(args.cache_to, exist_ok=True)
docker_args += ['--cache-to', f'type=local,dest={args.cache_to}']

docker_args += [
'-f', dockerfile,
'-t', f'{image_fullname}:{tag}',
]

if build_args:
for arg in build_args.split(','):
docker_args += ['--build-arg', arg.replace(' ', '_')]

docker_args += [context]

run_cmd('docker', *docker_args)

if args.push:
run_cmd('docker', 'push', f'{image_fullname}:{tag}')

os.chdir('../..')
Loading

0 comments on commit f2016a0

Please sign in to comment.