drone / go-convert

Package convert provides tools for converting pipeline configuration files to the Drone format.
Apache License 2.0
10 stars 8 forks source link

[downgrade] support `steps.spec.ports` #86

Closed jimsheldon closed 1 year ago

jimsheldon commented 1 year ago

Example GitHub yaml

name: service

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      nginx:
        image: nginx
        # Map port 8080 on the Docker host to port 80 on the nginx container
        ports:
          - 8080:80

Converts to this v1 yaml with ports set correctly

name: service
stages:
- name: test
  spec:
    platform:
      arch: amd64
      os: linux
    runtime:
      spec: {}
      type: cloud
    steps:
    - name: nginx
      spec:
        image: nginx
        ports:
        - 8080:80
      type: background
  type: ci
version: 1

Ports are lost when downgrading to v0 yaml

pipeline:
  identifier: default
  name: default
  orgIdentifier: default
  projectIdentifier: default
  properties:
    ci:
      codebase:
        build: <+input>
  stages:
  - stage:
      identifier: test
      name: test
      spec:
        cloneCodebase: true
        execution:
          steps:
          - step:
              identifier: nginx
              name: nginx
              spec:
                image: nginx
              timeout: ""
              type: Background
        platform:
          arch: Amd64
          os: Linux
        runtime:
          spec: {}
          type: Cloud
      type: CI

The step should downgrade to this

              - step:
                  type: Background
                  name: nginx
                  identifier: nginx
                  spec:
                    image: nginx
                    portBindings:
                      8080: "80"

NOTE: the port binding is not an int, it is a string, so quotes are required

jimsheldon commented 1 year ago

I have stared a branch with this feature https://github.com/drone/go-convert/compare/issue86-initial

example-6.yaml currently fails tests because this is seen as a mix of a string and an int, but the PortBindings struct only supports strings.

        ports:
        - 8080:80
        - 9090
jimsheldon commented 1 year ago

Should portBindings be omitted when using Kubernetes infra?

jimsheldon commented 1 year ago

Added in #87