Coder Social home page Coder Social logo

swift-server-app's Introduction

Swift + Docker

Swift Server App

Template to build a server app with Swift and Docker

Build Status

Tools

  • Xcode
  • Download from Xcode 8
  • Select Xcode 8 as default sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer/
  • swiftenv (optional since Swift built into Xcode 8 is the currently the latest version)
  • Install swiftenv via Homebrew
  • swiftenv rehash, swiftenv install <version> (see .swift-version)
  • Docker
  • Install from Docker website
  • Consider installing Kitematic to simplify Docker management

Build & Run with Swift Package Manager

  • Run swift build in root folder, wait until dependencies have been downloaded and server has been built
  • Run dependent services docker-compose -f docker-compose-dev.yml up
  • Run server ./.build/debug/SwiftServer
  • Test server by executing curl http://localhost:8090/ping
  • Test DB with curl -X POST localhost:8090/items, curl http://localhost:8090/items
  • Run unit tests with swift test

Build & Run with Xcode

  • Run swift package fetch in root folder to update dependencies
  • Generate Xcode project with swift package generate-xcodeproj
  • Run dependent services docker-compose -f docker-compose-dev.yml up
  • Open SwiftServer.xcodeproj in Xcode and Run SwiftServer scheme
  • Test server by executing curl http://localhost:8090/ping
  • Test DB with curl -X POST localhost:8090/items, curl http://localhost:8090/items
  • Run unit tests with CMD-U

Build & Run in Docker

  • Build image with docker-compose -f docker-compose-ci.yml build; tests a run as part of the build process
  • Run with docker-compose -f docker-compose-ci.yml up [-d] (stop: docker-compose down [-v], logs: docker-compose logs -f)
  • Test server by executing curl http://localhost:8090/ping
  • Test DB with curl -X POST localhost:8090/items, curl http://localhost:8090/items

Connect mongo to database server

  • docker-compose run --rm db mongo mongodb://db to connect to database -- use test, db.items.insert({}), db.items.find() to create sample data
  • Restart db instance to see that data persists in volume container

Handle managed volumes

  • docker inspect -f "{{json .Mounts}}" swiftserver_db_1 to find out mount point
  • docker volume ls -f dangling=true to find orphaned managed volumes
  • docker volume rm $(docker volume ls -qf dangling=true) to remove orphaned volumes

Provision on Digital Ocean

  • docker-machine create --driver digitalocean --digitalocean-access-token <token> SwiftServer
  • eval "$(docker-machine env SwiftServer)", eval "$(docker-machine env -u)"
  • docker-machine ssh SwiftServer to ssh into new machine
  • Export/import ssh setup: https://github.com/bhurlow/machine-share
  • docker compose -f docker-compose-prod.yml up to start services

Integration tests

  • Install newman with npm install newman --global
  • Run ./run-integration-tests.sh

swift-server-app's People

Contributors

choefele avatar

Stargazers

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

Watchers

 avatar  avatar

swift-server-app's Issues

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.