# start Tilt with no enabled resources
config.clear_enabled_resources()

k8s_yaml(helm(
    './charts/fp',
    values=['./charts/fp/values-dev.yaml'],
))

docker_build('fp/link2cid', './packages/link2cid')
docker_build(
    'fp/strapi',
    '.',
    dockerfile='strapi.dockerfile',
    target='release',
    live_update=[
        sync('./packages/strapi', '/app')
    ]
)

load('ext://uibutton', 'cmd_button')
cmd_button('postgres:restore',
        argv=['sh', '-c', 'cd letters && yarn install'],
        resource='postgres',
        icon_name='cloud_download',
        text='restore db from backup',
)


## Uncomment the following for fp/next in dev mode
## this is useful for changing the UI and seeing results
docker_build(
    'fp/next',
    '.',
    dockerfile='next.dockerfile',
    target='dev',
    live_update=[
        sync('./packages/next', '/app')
    ]
)

## Uncomment the following for fp/next in production mode
## this is useful to test how fp/next will behave in production environment
## note: there is no live_update here. expect slow rebuilds in response to code changes
# docker_build('fp/next', '.', dockerfile='next.dockerfile')


k8s_resource(
    workload='link2cid', 
    port_forwards=3939,
    links=[
        link('http://localhost:3939/health', 'link2cid Health')
    ]
)

k8s_resource(
    workload='ipfs-pod',
    port_forwards=['5001'],
    links=[
      link('http://localhost:5001/webui', 'IPFS Web UI')
   ]
)

k8s_resource(
    workload='next-pod',
    port_forwards=['3000'],
)
k8s_resource(
    workload='strapi-pod',
    port_forwards=['1337'],
    links=[
      link('http://localhost:1337/admin', 'Strapi Admin UI')
    ]
)

k8s_resource(
    workload='postgres-pod',
)
k8s_resource(
    workload='pgadmin-pod',
    port_forwards=['5050']
)


# v1alpha1.extension_repo(name='default', url='https://github.com/tilt-dev/tilt-extensions')
# v1alpha1.extension(name='ngrok', repo_name='default', repo_path='ngrok')

# settings = read_json('tilt_option.json', default={})
# default_registry(settings.get('default_registry', 'sjc.vultrcr.com/fpcontainers'))

config.set_enabled_resources([
    'pgadmin-pod',
    'postgres-pod',
    'strapi-pod', 
    'next-pod',
    'ipfs-pod',
    'link2cid',
])