# This source file is part of the Swift open source project
#
# Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

# this file is not designed to be run directly
# instead, use the docker-compose.<os>.<swift> files
# eg docker-compose -f Utilities/docker/docker-compose.yaml -f Utilities/docker/docker-compose.2004.57.yaml run test
version: "3"

services:

  runtime-setup:
    image: swift-package-manager:default
    build:
      context: .
      dockerfile: Dockerfile

  common: &common
    image: swift-package-manager:default
    depends_on: [runtime-setup]
    volumes:
      # ssh, caches
      - ~/.ssh:/root/.ssh
      - ~/.cache:/root/.cache
      - ~/.swiftpm/cache:/root/.swiftpm/cache
      - ~/.swiftpm/configuration:/root/.swiftpm/config # old location, remove after 5.6
      - ~/.swiftpm/configuration:/root/.swiftpm/configuration
      - ~/.swiftpm/security:/root/.swiftpm/security
      # swift-package-manager code
      - ../..:/code/swift-package-manager:z
      # bootstrap script requires dependencies to be pre-fetched and in a specific place
      - ../../../swift-tools-support-core:/code/swift-tools-support-core:z
      - ../../../yams:/code/yams:z
      - ../../../swift-argument-parser:/code/swift-argument-parser:z
      - ../../../swift-crypto:/code/swift-crypto:z
      - ../../../swift-driver:/code/swift-driver:z
      - ../../../swift-llbuild:/code/llbuild:z
      - ../../../swift-system:/code/swift-system:z
      - ../../../swift-collections:/code/swift-collections:z
      - ../../../swift-asn1:/code/swift-asn1:z
      - ../../../swift-certificates:/code/swift-certificates:z
    working_dir: /code/swift-package-manager
    cap_drop:
      - CAP_NET_RAW
      - CAP_NET_BIND_SERVICE

  build:
    <<: *common
    command: /bin/bash -cl "swift build"

  test:
    <<: *common
    command: /bin/bash -cl "swift test --parallel"

  bootstrap-clean:
    <<: *common
    command: /bin/bash -cl "./Utilities/bootstrap clean"

  bootstrap-build:
    <<: *common
    command: /bin/bash -cl "./Utilities/bootstrap build"

  bootstrap-test:
    <<: *common
    command: /bin/bash -cl "./Utilities/bootstrap test"

  # util

  shell:
    <<: *common
    entrypoint: /bin/bash
