Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Travis CIのBuild Matrixを活用して、Swift製ライブラリをLinux対応させる

Travis CIのBuild Matrixを活用して、Swift製ライブラリをLinux対応させる

「CI/CD Test Night #4」の発表資料です #cicd_test_night

Sho Ikeda

June 20, 2019
Tweet

More Decks by Sho Ikeda

Other Decks in Programming

Transcript

  1. Travis CIͷBuild MatrixΛ׆༻ͯ͠
    Swift੡ϥΠϒϥϦΛLinuxରԠͤ͞Δ
    Sho Ikeda / @ikesyo
    CI/CD Test Night #4
    2019-06-20 Thu
    #cicd_test_night

    View full-size slide

  2. Sho Ikeda / @ikesyo
    • ͍͚͠ΐʔʗ஑ా ᠳ
    • גࣜձࣾ͸ͯͳʢژ౎ΦϑΟεʣ
    • εϚʔτϑΥϯΞϓϦ։ൃ
    • iOS / Android / React Native
    • Swiftίϛολʔ
    • https://twitter.com/ikesyo
    • https://github.com/ikesyo

    View full-size slide

  3. Agenda
    • Swift Packages
    • Swift on Linux
    • ϩʔΧϧ։ൃ
    • Docker
    • CI؀ڥ
    • Travis CI
    • Build Matrix
    • swiftenv
    • ͦͷଞͷCIαʔϏε

    View full-size slide

  4. Swift੡ϥΠϒϥϦ

    View full-size slide

  5. Swift Packages

    View full-size slide

  6. Swift Package Manager (SwiftPM)
    • The Package Manager for the Swift Programming Language
    • Bundled with Swift
    • Introduced in Swift 3 (2016)
    • ݱࡏ͸Swift 5ʢ2019೥ळʹSwift 5.1ʣ
    • https://github.com/apple/swift-package-manager

    View full-size slide

  7. Swift Package Manager (SwiftPM)
    • Package.swift
    • ϚχϑΣετϑΝΠϧʢύοέʔδఆٛʣ
    • Targets, Products, Dependencies, Build Settings, ...

    View full-size slide

  8. // swift-tools-version:5.0
    import PackageDescription
    let package = Package(
    name: "Himotoki",
    platforms: [
    .macOS(.v10_10), .iOS(.v8), .tvOS(.v9), .watchOS(.v2)
    ],
    products: [
    .library(name: "Himotoki", targets: ["Himotoki"]),
    ],
    targets: [
    .target(name: "Himotoki", dependencies: [], path: "Sources"),
    .testTarget(name: "HimotokiTests", dependencies: ["Himotoki"]),
    ],
    swiftLanguageVersions: [.v5]
    )

    View full-size slide

  9. Swift Package Manager (SwiftPM)
    • Uses
    • [NEW!] iOS/macOS/tvOS/watchOS Apps
    (since Xcode 11)
    • CLI tools
    • Server-side Swift

    View full-size slide

  10. Server-side Swift

    View full-size slide

  11. Swift on Linux

    View full-size slide

  12. Swift on Linux
    • https://swift.org/about/#linux
    • Official: Ubuntu 18.04/16.04/14.04
    • Community: Fedora 27, Debian 9.5
    • ී௨ͷSwiftϓϩάϥϚʔ͸macOSͱXcodeͰ։ൃ͍ͯ͠Δ
    • Ͳ͏΍ͬͯLinuxͰϏϧυͯ͠ςετ͢Δʁ
    • ޓ׵ੑ͸Ͳ͏ͳͷʁ

    View full-size slide

  13. ϩʔΧϧ։ൃ

    View full-size slide

  14. swift-docker
    • An Ubuntu 16.04 and Ubuntu 18.04 Docker image for Swift.
    • https://github.com/apple/swift-docker
    • https://hub.docker.com/_/swift/
    • $ docker run -it -v `pwd`:/project swift bash
    • $ cd project; swift build

    View full-size slide

  15. ෳ਺όʔδϣϯͰςετ
    • ෳ਺όʔδϣϯαϙʔτɺޓ׵ੑͷ֬อ
    • $ docker run -it -v `pwd`:/project swift:5.0 bash
    • $ docker run -it -v `pwd`:/project swift:4.2 bash
    • $ docker run -it -v `pwd`:/project swift:4.1 bash
    • ...

    View full-size slide

  16. Travis CI
    • Build Matrix
    • https://docs.travis-ci.com/user/build-matrix/
    • ෳ਺ͷδϣϒΛฒྻ࣮ߦ͢Δ
    • Linux͚ͩ͡Όͳͯ͘macOS΋࢖͑Δ
    • https://docs.travis-ci.com/user/reference/osx/
    • macOSͱLinuxΛ·ͱΊͯςετͰ͖Δ
    • Always free for open source projects
    • https://travis-ci.com/plans
    • OSS͸ແྉͰLinux΋macOS΋࢖͑ΔʢmacOSͷಉ࣮࣌ߦ਺͸2·Ͱʣ
    • 1δϣϒ͋ͨΓͷϏϧυ࣌ؒͷ্ݶ͕50෼

    View full-size slide

  17. Travis CI
    • Build Matrix
    • https://docs.travis-ci.com/user/build-matrix/
    • ෳ਺ͷδϣϒΛฒྻ࣮ߦ͢Δ
    • Linux͚ͩ͡Όͳͯ͘macOS΋࢖͑Δ
    • https://docs.travis-ci.com/user/reference/osx/
    • macOSͱLinuxΛ·ͱΊͯςετͰ͖Δ
    • Always free for open source projects
    • https://travis-ci.com/plans
    • OSS͸ແྉͰLinux΋macOS΋࢖͑ΔʢmacOSͷಉ࣮࣌ߦ਺͸2·Ͱʣ
    • 1δϣϒ͋ͨΓͷϏϧυ࣌ؒͷ্ݶ͕50෼

    View full-size slide

  18. Build Matrix
    • 2*2*2ͷ8௨Γ
    rvm:
    - 2.5
    - 2.2
    gemfile:
    - gemfiles/Gemfile.rails-3.2.x
    - gemfiles/Gemfile.rails-3.0.x
    env:
    - ISOLATED=true
    - ISOLATED=false

    View full-size slide

  19. Build Matrix
    matrix:
    include:
    - rvm: 2.5
    gemfile: gemfiles/Gemfile.rails-3.2.x
    env: ISOLATED=false
    - rvm: 2.5
    gemfile: gemfiles/Gemfile.rails-3.2.x
    env: ISOLATED=true

    View full-size slide

  20. Build Matrix
    • macOSͱLinuxͦΕͧΕͰɺෳ਺όʔδϣϯͷSwiftΛςετ
    ͢Δ

    View full-size slide

  21. Build Matrix
    language: generic
    matrix:
    include:
    - &swiftpm_darwin
    name: SwiftPM / Darwin / Swift 4.2
    os: osx
    osx_image: xcode10.1
    script: swift test
    - <<: *swiftpm_darwin
    name: SwiftPM / Darwin / Swift 5.0
    osx_image: xcode10.2
    - &swiftpm_linux
    name: SwiftPM / Linux / Swift 4.2
    os: linux
    sudo: required
    dist: trusty
    env:
    - SWIFT_VERSION=4.2.4
    install: eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
    script: swift test
    - <<: *swiftpm_linux
    name: SwiftPM / Linux / Swift 5.0
    env:
    - SWIFT_VERSION=5.0
    - <<: *swiftpm_linux
    name: SwiftPM / Linux / Swift 5.1 Development
    env:
    - SWIFT_VERSION=5.1-DEVELOPMENT-SNAPSHOT-2019-05-28-a

    View full-size slide

  22. - &swiftpm_darwin
    name: SwiftPM / Darwin / Swift 4.2
    os: osx
    osx_image: xcode10.1
    script: swift test
    - <<: *swiftpm_darwin
    name: SwiftPM / Darwin / Swift 5.0
    osx_image: xcode10.2

    View full-size slide

  23. - &swiftpm_linux
    name: SwiftPM / Linux / Swift 4.2
    os: linux
    sudo: required
    dist: trusty
    env:
    - SWIFT_VERSION=4.2.4
    install: eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
    script: swift test
    - <<: *swiftpm_linux
    name: SwiftPM / Linux / Swift 5.0
    env:
    - SWIFT_VERSION=5.0
    - <<: *swiftpm_linux
    name: SwiftPM / Linux / Swift 5.1 Development
    env:
    - SWIFT_VERSION=5.1-DEVELOPMENT-SNAPSHOT-2019-05-28-a

    View full-size slide

  24. swiftenv
    • https://github.com/kylef/swiftenv
    • Swift Version Manager
    • ͲͪΒ͔ͰόʔδϣϯΛࢦఆ
    • ϑΝΠϧ: .swift-version
    • ؀ڥม਺: SWIFT_VERSION
    • $ eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
    • swiftenvࣗମͱɺࢦఆ͞ΕͨSwiftͷόʔδϣϯΛΠϯετʔϧ
    • Travis CIͷδϣϒͰDockerΛ࢖͏ͷ͸໘౗ͳͷͰ͜Ε͕ศར
    • https://docs.travis-ci.com/user/docker/

    View full-size slide

  25. ͦͷଞͷCIαʔϏε

    View full-size slide

  26. ͦͷଞͷCIαʔϏε
    • macOSͱLinux/Dockerͷ྆ํ͕࢖͑Δ͜ͱ͕લఏ
    • Bitrise
    • CircleCI
    • Azure Pipelines

    View full-size slide

  27. Bitrise
    • https://www.bitrise.io/
    • OSS޲͚ͷແྉϓϥϯ͋Γ
    • https://blog.bitrise.io/free-developer-plan-features-for-open-source-
    projects-on-bitrise
    • ฒྻ࣮ߦෆՄ
    • Ϗϧυ࣌ؒ: 45෼·Ͱ
    • Ϗϧυճ਺: ແ੍ݶ
    • Linux/Android StackͰ͸࢖༻͢ΔDockerΠϝʔδΛࢦఆͰ͖Δ

    View full-size slide

  28. CircleCI
    • https://circleci.com/
    • OSS޲͚ͷແྉϓϥϯ͋Γ
    • https://circleci.com/pricing/
    • Linux: 4ฒྻ
    • macOS: 1ฒྻʢϝʔϧͰ࿈བྷ͢Δඞཁ͋Γʣ

    View full-size slide

  29. CircleCI
    • Workflows
    • https://circleci.com/docs/2.0/workflows-overview/
    • Travis CIͷBuild MatrixͷΑ͏ʹॊೈͳฒྻ࣮ߦ͕Ͱ͖Δ
    • Linux: DockerϕʔεͳͷͰswiftenv͍Βͣ
    • ॊೈͳΩϟογϡ੍ޚ
    • https://circleci.com/docs/2.0/caching/

    View full-size slide

  30. Azure Pipelines
    • https://azure.microsoft.com/ja-jp/services/devops/pipelines/
    • OSS޲͚ͷແྉϓϥϯ͋Γ
    • LinuxɺmacOSɺWindowsͷ߹ܭͰ10ฒྻʢ੍࣌ؒݶͳ͠ʣ
    • Linux: DockerϕʔεͳͷͰswiftenv͍Βͣ
    • Azure Pipeline - Speaker Deck
    • iOS Test Night #10Ͱͷ@giginet͞Μͷൃද

    View full-size slide

  31. !
    Happy Swift on Linux Life

    View full-size slide

  32. Thank you
    Sho Ikeda / @ikesyo

    View full-size slide