Coder Social home page Coder Social logo

swift-docker's Introduction

swift-docker

A command line tool for building, testing & running your swift package in a docker container.

Quick start for macOS

brew install iainsmith/formulae/swift-docker # Install swift docker
git clone https://github.com/jpsim/Yams.git # Clone an example package
cd Yams && swift test # Run the tests on your machine
swift docker test # Run the tests in a container
swift docker test --swift 5.1 # Check if the tests pass on swift 5.1
swift docker write-dockerfile # Write a ./Dockerfile to the repo

Features

  • Test swift packages in one command swift docker test
  • Use custom images - swift docker test --image vapor/swift:latest
  • swift docker build/test/run commands mirror swift build/test/run
  • Run your vapor application in a container - swift docker vapor
  • Cached builds using docker volumes
  • Use a mix of docker volumes & bind mounts for fast, small builds.
  • Uses the swift docker image that matches the Package.swift manifest.
  • Quickly free up space - swift docker cleanup
  • Create a dockerfile for your project
  • Quickly print a command to run the swift repl in the container - swift docker repl
  • Create a .dockerignore file to avoid adding .git directory to the image
  • Support multistage slim builds
  • Log output to a file
  • cmake build for running on Windows

Install swift-docker

Install with Homebrew

brew install iainsmith/formulae/swift-docker
Install from source
> git clone https://github.com/iainsmith/swift-docker-cli.git
> cd swift-docker
> swift build -c release --disable-sandbox
# copy the binary to somewhere in your path.
> cp ./.build/release/swift-docker ~/bin

And install docker if you don't have it already
  • Download the Docker Mac App.
  • Or alternatively install via homebrew brew cask install docker

Usage

OVERVIEW: A simple workflow for building & testing swift packages with docker

Run swift docker <subcommand> --help for subcommand details
Reference - Offical docker images: https://hub.docker.com/_/swift

Examples:

swift docker test
swift docker build -- --configuration release
swift docker run your-executable --flag1
swift docker vapor

USAGE: swift-docker <subcommand>

OPTIONS:
-h, --help              Show help information.

SUBCOMMANDS:
build                   Build your swift package in a docker container.
test                    Test your swift package in a docker container.
run                     Run your swift package in a docker container.
vapor                   Run your vapor web application in a container.
build-image             Build a docker image for your swift package.
repl                    print the command to run the swift repl in a container.
cleanup                 Remove temporary docker images.
write-dockerfile        Write a dockerfile to disk.

Vapor

Run swift docker vapor to run your vapor application in a docker container. This is significantly faster than workflows that require you to build a docker image as we bind the local directory into the container, and cache the build folder.

  • You can pass custom arguments to your application by running swift docker vapor -- arg1 --flag1.
  • Currently the environment is set to production & the port is set to 8080.
  • The default docker image is swift:latest. You can use a custom image with swift docker vapor --image vapor/swift:latest

Docker labels

Each docker image created by swift-docker is tagged with two labels.

LABEL com.swiftdockercli.action="test/build"
LABEL com.swiftdockercli.folder="your-project-name"

Running docker volume ls --filter label=com.swiftdockercli.action=test will list volumes created by swift-docker test.

Contributing

If you have suggestions for new commands, features or bug fixes. Please raise an issue or open a PR.

If you find this tool useful in your workflow let me know on twitter @_iains

Credits

swift-docker is built on top of

swift-docker's People

Contributors

iainsmith avatar neilkimmett avatar ole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

swift-docker's Issues

Add swift docker repl command

Add a swift docker repl command so it's easy to get a swift repl in a container.

docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --security-opt apparmor=unconfined

See SwiftDocOrg/DocTest#1 for details

Thanks to @heckj for digging into this.

question - closed connection?

I'm using this as a tool for testing some packages for Linux support, and every now and then the output is unexpectedly terminated and I'm dropped back to the shell.

Re-running picks up and continues, but I thought I'd mention it.

The project I'm working on DocTest, and it's happened repeatedly enough that this might be reproducible:

  • git clone https://github.com/SwiftDocOrg/DocTest.git
  • cd DocTest
  • swift docker test --args --enable-test-discovery

First time through, I had output that looked like:

-> swift test
  Fetching https://github.com/apple/swift-syntax.git
  Fetching https://github.com/jpsim/Yams.git
  Fetching https://github.com/kean/Future
  Fetching https://github.com/apple/swift-argument-parser.git
  Fetching https://github.com/SwiftDocOrg/TAP.git
  Cloning https://github.com/kean/Future
  Resolving https://github.com/kean/Future at 1.4.0
  Cloning https://github.com/jpsim/Yams.git
  Resolving https://github.com/jpsim/Yams.git at 3.0.0
  Cloning https://github.com/apple/swift-syntax.git
  Resolving https://github.com/apple/swift-syntax.git at 0.50200.0
  Cloning https://github.com/apple/swift-argument-parser.git
  Resolving https://github.com/apple/swift-argument-parser.git at 0.0.5
  Cloning https://github.com/SwiftDocOrg/TAP.git
  Resolving https://github.com/SwiftDocOrg/TAP.git at 0.1.1
  [7/93] Compiling scanner.c%

And repeated commands then go through normally, finishing the compile and running the tests. I suspect that something is seg-faulting and dropping the container, but I wasn't entirely sure how to determine that or get any additional debugging to help isolate the underlying issue.

repl - tty support

See if we can get swift-docker repl to use tty. This would unblock being able to build swift docker lldb

package at '/src' is using Swift tools version 5.4.0 but the installed version is 5.3.0

$ swift docker test --swift 5.4.1 
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
/src: error: package at '/src' is using Swift tools version 5.4.0 but the installed version is 5.3.0

The manifest is indeed 5.4. The macOS installed Swift is 5.4. I cannot say where it is trying to get 5.3 from.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.