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

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

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

7ddcca09c00a2744b983974225447d19?s=128

Sho Ikeda

June 20, 2019
Tweet

Transcript

  1. Travis CIͷBuild MatrixΛ׆༻ͯ͠ Swift੡ϥΠϒϥϦΛLinuxରԠͤ͞Δ Sho Ikeda / @ikesyo CI/CD Test

    Night #4 2019-06-20 Thu #cicd_test_night
  2. Sho Ikeda / @ikesyo • ͍͚͠ΐʔʗ஑ా ᠳ • גࣜձࣾ͸ͯͳʢژ౎ΦϑΟεʣ •

    εϚʔτϑΥϯΞϓϦ։ൃ • iOS / Android / React Native • Swiftίϛολʔ • https://twitter.com/ikesyo • https://github.com/ikesyo
  3. Agenda • Swift Packages • Swift on Linux • ϩʔΧϧ։ൃ

    • Docker • CI؀ڥ • Travis CI • Build Matrix • swiftenv • ͦͷଞͷCIαʔϏε
  4. Swift

  5. None
  6. Swift੡ϥΠϒϥϦ

  7. Swift Packages

  8. 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
  9. Swift Package Manager (SwiftPM) • Package.swift • ϚχϑΣετϑΝΠϧʢύοέʔδఆٛʣ • Targets,

    Products, Dependencies, Build Settings, ...
  10. // 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] )
  11. Swift Package Manager (SwiftPM) • Uses • [NEW!] iOS/macOS/tvOS/watchOS Apps

    (since Xcode 11) • CLI tools • Server-side Swift
  12. Server-side Swift

  13. Swift on Linux

  14. 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ͰϏϧυͯ͠ςετ͢Δʁ • ޓ׵ੑ͸Ͳ͏ͳͷʁ
  15. ϩʔΧϧ։ൃ

  16. Docker

  17. 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
  18. None
  19. ෳ਺όʔδϣϯͰςετ • ෳ਺όʔδϣϯαϙʔτɺޓ׵ੑͷ֬อ • $ 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 • ...
  20. CI؀ڥ

  21. Travis CI

  22. 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෼
  23. 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෼
  24. 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
  25. 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
  26. Build Matrix • macOSͱLinuxͦΕͧΕͰɺෳ਺όʔδϣϯͷSwiftΛςετ ͢Δ

  27. 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
  28. - &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
  29. - &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
  30. swiftenv

  31. 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/
  32. ͦͷଞͷCIαʔϏε

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

  34. 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ΠϝʔδΛࢦఆͰ͖Δ
  35. CircleCI • https://circleci.com/ • OSS޲͚ͷແྉϓϥϯ͋Γ • https://circleci.com/pricing/ • Linux: 4ฒྻ

    • macOS: 1ฒྻʢϝʔϧͰ࿈བྷ͢Δඞཁ͋Γʣ
  36. CircleCI • Workflows • https://circleci.com/docs/2.0/workflows-overview/ • Travis CIͷBuild MatrixͷΑ͏ʹॊೈͳฒྻ࣮ߦ͕Ͱ͖Δ •

    Linux: DockerϕʔεͳͷͰswiftenv͍Βͣ • ॊೈͳΩϟογϡ੍ޚ • https://circleci.com/docs/2.0/caching/
  37. 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͞Μͷൃද
  38. ! Happy Swift on Linux Life

  39. Thank you Sho Ikeda / @ikesyo