sql server devops jumpstart

57
SQL SERVER DEVOPS JUMPSTART DON’T FEAR THE SHELL Ori Donner SQL Server DBA & DevOps at Crow Electronic Engineering LTD Dec 2016 Data platform Meetup Israel

Upload: ori-donner

Post on 15-Apr-2017

507 views

Category:

Software


1 download

TRANSCRIPT

Page 1: SQL Server DevOps Jumpstart

SQL

SERVER

DEVOPS

JUMPSTART

DON’T FEAR THE SHELL

Ori Donner SQL Server DBA & DevOps at Crow Electronic Engineering LTD Dec 2016 Data platform Meetup Israel

Page 2: SQL Server DevOps Jumpstart

MEETING SUBJECT :

SQL Server Database Application Lifecycle Management

TARGET AUDIENCE :

SQL Server developers.

DBA’s.

DevOps.

Page 3: SQL Server DevOps Jumpstart

AGENDA

• Agile

• DevOps

• Version Control

• Branching & Versioning strategies

• SQL Server database ALM tools

• Q/A

Page 4: SQL Server DevOps Jumpstart

Agile

Page 5: SQL Server DevOps Jumpstart

AGILE

The shift from plan driven software to adaptive planning approach :

Success == Project is advancing according to plan (prediction).

What happens if the requirements are not stable?

1. Stabilize the requirements.

2. Break the equation.

Come up with a software development process that is tolerant towards

changes (competitive advantage).

Page 6: SQL Server DevOps Jumpstart

AGILE

Feedback : Setting up fast feedback loop

• From developer perspective :

• How fast you can drive the Mars rover? Speed of feedback effects

your software development performance .

• From user perspective :

• Get fast feedback from the user and develop what is necessary

for your user.

Page 7: SQL Server DevOps Jumpstart

AGILE

Feedback : Measurements

Constant feedback loop of software development process :

• Does our software integrate?

• Does it built and perform well?

• What stage of readiness to production is it?

Feedback loop for the basic health of the software.

Page 8: SQL Server DevOps Jumpstart

AGILE

Feedback : Pair Programming

You can only use half of your brain at a time.

The only way to apply one full brain to software development is to use

two half brains at one time.

Not two people working in one project, but one brain working on one

project.

Page 9: SQL Server DevOps Jumpstart

DevOps

Page 10: SQL Server DevOps Jumpstart

DEVOPS

• At the Agile 2008 conference, Andrew Clay Shafer and Patrick Debois

discussed "Agile Infrastructure". The term "DevOps" was popularized

through a series of DevOpsdays starting in 2009 in Belgium.

• DevOps main issue is to constantly improve software delivery.

• Improve the software.

• Improve the environment to which you are delivering.

• Improve the delivery process.

Page 11: SQL Server DevOps Jumpstart

DEVOPS PIPELINE

BUILD

Source code

TEST DEPLOY

Software

Process

Page 12: SQL Server DevOps Jumpstart

DEVOPS PIPELINE • Code - Code development and review, Version control tools, code

merging.

• Build - continuous integration tools, build status.

• Test - Test and results determine performance.

• Package - Artifact repository, application pre-deployment staging.

• Release - Change management, release approvals, release automation.

• Configure - Infrastructure configuration and management, Infrastructure

as Code tools (Vagrant - virtualization, Docker - containers).

• Monitor - Applications performance monitoring, end user experience.

Page 13: SQL Server DevOps Jumpstart

DEVOPS CYCLE

Page 14: SQL Server DevOps Jumpstart

DEVOPS PROCESS & TOOLS

BUILD

Source code

TEST DEPLOY

Software

Git

GitLab-CI

Process

CMD Tools

SSDT Developer IDE Tool

MSBuild MSTest sqlpackage

DevOps IDE Tool

Page 15: SQL Server DevOps Jumpstart

CONTINUOUS INTEGRATION

• Frequent small check ins instead of waiting until the whole piece is

done. Every developer checks his code multiple times a day.

• Every time someone checks in the code is verified by an automated

build system (Max respond time of 10 min).

• Fix the broken build right away.

Page 16: SQL Server DevOps Jumpstart

CONTINUOUS DELIVERY

• The capability to get software deployed to any particular environment ,

in the delivery pipeline, at any given time :

• In case of existing environment you set the environments

configuration.

• In case of where the environment does not exist you need to

provision the environment.

• Keep the product releasable.

• Build the quality inside the process (speed + quality)

• Test in an environment closest to production.

Page 17: SQL Server DevOps Jumpstart

CONTINUOUS DEPLOYMENT

• Continuous Deployment is the process of checking into master,

running all the tests and if everything goes green it is automatically

pushed to production (usually for .com project).

Page 18: SQL Server DevOps Jumpstart

Version Control

Page 19: SQL Server DevOps Jumpstart

VERSION CONTROL BASICS

• Tracking changes that happen within directories or files : modifying a

file, deleting a directory, adding a new file, moving files .

• The set of files or directories that are under version control are more

commonly called a repository.

• The version control system will wait for you to submit your changes as

a single collection of actions. In version control, this collection of

actions is known as a commit.

• When a commit is made, the changes are recorded as

a changeset and given a unique hash

(like 846eee7d92415cfd3f8a936d9ba5c3ad345831e5).

Page 20: SQL Server DevOps Jumpstart

VERSION CONTROL BASICS

• The version control system will provide a way to view the difference

between the conflicting versions, allowing you to make a choice to edit

the files manually , to merge the options, or allow one revision to win over

the other.

• Since each commit is recorded as a change to a file or set of files and

directories, it is sometimes useful to view what changed between

revisions (Diffing) .

• A branch allows you to create a copy (or snapshot) of the repository that

you can modify in parallel without altering the main set. You can continue

to commit new changes to the branch as you work, while others commit

to the trunk or master without the changes affecting each other.

Page 21: SQL Server DevOps Jumpstart

VERSION CONTROL BASICS

• By merging the branch with the trunk or master (or even another

branch), your version control tool will attempt to seamlessly merge

each file and line of code automatically. Once a branch is merged it

then updates the trunk or master with the latest files.

Page 22: SQL Server DevOps Jumpstart

CENTRALIZED

• TFVC • Subversion

Page 23: SQL Server DevOps Jumpstart

CENTRALIZED

Benefits

• It is easy to understand.

• You have more control over

users and access .

• Simple to get started.

Drawbacks

• Dependent on access to the

server.

• It can be slower because

every command connects to

the server.

• Branching and merging tools

are difficult to use.

Page 24: SQL Server DevOps Jumpstart

DISTRIBUTED

• Git • Mercurial

Page 25: SQL Server DevOps Jumpstart

DISTRIBUTED

Benefits

• More powerful and detailed

change tracking, which means

less conflicts.

• No server necessary

• Branching and merging is more

reliable.

• It’s fast.

Drawbacks

• The distributed model is

harder to understand.

• The revisions are not

incremental numbers, which

make them harder to

reference.

Page 26: SQL Server DevOps Jumpstart

GIT

• Distributed version control system, developed by Junio Hamano &

Linus Torvalds.

• Runs on major operating systems :

• Runs on Windows (download : https://git-scm.com/downloads).

• Embedded in VS 2013, VS code, TFS & VS Online.

• posh-git for powershell (installation : https://github.com/dahlbyk/posh-git).

With chocolatey package manager :

choco install git

choco install poshgit

Page 27: SQL Server DevOps Jumpstart

GITLAB

• GitLab is a web-based repository manager that lets teams collaborate

on code, duplicate code to safely create and edit new projects, then

merge finished code into existing projects..

• GitLab Community Edition (CE) - free, self hosted

application, support from Community

• GitLab has everything GitHub has, and more - giving teams increased

control over their repositories.

Page 28: SQL Server DevOps Jumpstart

Branching

Page 29: SQL Server DevOps Jumpstart

BRANCHING CONCEPTS

• Trunk-based : one master branch.

• Feature driven : feature branches with one master brunch.

• Release branches : install software.

• Git flow : 2 main branches. application life cycle for installed apps.

• Open source : fork , squash and pull request.

Page 30: SQL Server DevOps Jumpstart

GITFLOW

• GitFlow is branching

and release

management strategy

that helps developers

keep track of features,

hotfixes and releases in

bigger software

projects.

Page 31: SQL Server DevOps Jumpstart

MAIN BRANCHES

• The central repo holds two main

branches with an infinite lifetime:

• master : reflects a production-

ready state source code.

• develop : reflects development

changes for the next release.

Page 32: SQL Server DevOps Jumpstart

SUPPORTING BRANCHES

• Unlike the main branches, these branches always have a limited life

time, since they will be removed eventually.

• Feature branches

• Release branches

• Hotfix branches

Page 33: SQL Server DevOps Jumpstart

FEATURE BRANCHES

• Are used to develop new

features for the upcoming or a

distant future release. The

branch will exist as long as the

feature is in development, but

will eventually be merged back

into develop.

Page 34: SQL Server DevOps Jumpstart

RELEASE

• supports preparation of a new

production release. They allow

for minor bug fixes and preparing

meta-data for a release. By doing

all of this work on a release

branch, the develop branch is

cleared to receive features for

the next big release.

* major/minor version number bumping

Page 35: SQL Server DevOps Jumpstart

HOTFIX

• HotFix : Team

members (on

the develop branch)

can continue, while

another person is

preparing a quick

production fix.

* only patch version number bumping

Page 36: SQL Server DevOps Jumpstart

Versioning

Page 37: SQL Server DevOps Jumpstart

WHAT TO VERSION

• Your product.

• Libraries, builds.

• Public and private(internal versioning)

• DB schemas.

• Infrastructure configuration : Containers (Docker)

• Public and private API : DreamFactory (reusable REST API)

Page 38: SQL Server DevOps Jumpstart

VERSIONING MODELS

• Numeric : Major.Minor > Major.Minor.Patch > Major.Minor.Patch.Build

• Date based : Major.Minor.Date

• Marketing versions : Whatever PM or marketing decide

• Semantic versioning : Major.Minor.Patch-prerelease+metadata

Page 39: SQL Server DevOps Jumpstart

SEMANTIC VERSIONING

• Exact rules how you change the version.

• 0.1.4-b45+d3e760

• 0.1.5-46

• 0.2.1-prerelease+b538

• 1.0.0-alpha

• 1.3.9-beta

• 2.0.0

Page 40: SQL Server DevOps Jumpstart

SEMANTIC VERSIONING

Given a version number MAJOR.MINOR.PATCH, increment the:

• MAJOR version when you make incompatible API changes,

• MINOR version when you add functionality in a backwards-compatible

manner, and

• PATCH version when you make backwards-compatible bug fixes.

• Additional labels for pre-release and build metadata are available as

extensions to the MAJOR.MINOR.PATCH format.

Page 41: SQL Server DevOps Jumpstart

GITVERSION

• GitVersion is a tool to help you achieve Semantic Versioning on your

project.

• GitVersion looks at your git history and works out the semantic

version (semver.org) of the commit being built.

• By default GitVersion returns a json object to stdout containing all

the variables which GitVersion generates.

Page 42: SQL Server DevOps Jumpstart

Database

Application

Life

Management

Page 43: SQL Server DevOps Jumpstart

THE MAIN CHALLENGE

• In application versioning, old binaries are being replaced with new

binaries after each deployment.

• In database versioning a database cannot be overwritten because it

contains data. The concept is to create incremental SQL scripts to

modify the existing database (tools like Liquibase).

Page 44: SQL Server DevOps Jumpstart

DATABASE SCHEMA MANAGEMENT

Transformational process

• Physical schema : Connected database development mode (SSMS).

• Seed script, starts initial version of the database.

• Change scripts are kept in release folder .

• In order to recreate the database in its current version, you have to

execute the seed script with all the changes in the right order.

• May fail in case of server drift or unrecorded changes made to the

database (patches, hot fixes).

Page 45: SQL Server DevOps Jumpstart

DATABASE SCHEMA MANAGEMENT

State based methodology

• Virtual schema : Data Tier Application Framework (DACFx).

• Keep your SQL Server Database in a code form, where you can

compile validate and source control.

• The tool creates the change scripts for you.

• Focus on the schema model not on how to get there.

• Need to ensure sufficient log space is available for upgrade process.

Page 46: SQL Server DevOps Jumpstart

MICROSOFT TOOLS

• SSMS : Connected database development.

• SMO (Server Management Object) : .net object oriented programming

(abstraction) : , C# VS project.

• SSDT : Data Tier Application Framework (DACFx).

ssdt smo ssms + + - Virtual schema

+ - - State based + - + Native (T-SQL)

Page 47: SQL Server DevOps Jumpstart

SQL SERVER DATA TOOL

• Project system for database development (like C#).

• Build time validation : validation of T-SQL code.

• Online/offline editing : object explorer for online editing.

• Database publishing with extensibility : deploying from VS.

• Schema comparison : between project/dacpac/database.

• Database Unit Testing.

• SSDT in Visual Studio 2015 (not as a feature in SQL Server

installation).

Page 48: SQL Server DevOps Jumpstart

Command line toolbox

Page 49: SQL Server DevOps Jumpstart

MSBUILD.EXE

MSBuild is a build platform for Microsoft Visual Studio, included in VS

since visual studio 2013 .

• MSBuild project file is being created behind the scenes while writing

code in VS IDE (e.g. Project_name.sqlproj )

• The build process output is a Data Tier Application Package file (e.g.

Project_name.dacpac).

Page 50: SQL Server DevOps Jumpstart

MSBUILD FILE SCHEMA

<?xml version="1.0" encoding="utf-8"?>

<Project ToolsVersion="3.5“ xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Import Project="$(MSBuildExtensionsPath)\..\Microsoft.Data.Tools.Schema.SqlTasks.targets“/>

<Target Name="Default">

</Target>

<PropertyGroup>

</PropertyGroup>

<ItemGroup>

</ItemGroup>

</Project>

Root element

(req) Attribute

Default Name Space

(req)

Import element : imports tasks,targets and properties for SSDT

Page 51: SQL Server DevOps Jumpstart

.DACPAC

• DAC : A data-tier application is a logical database management entity

that defines all of the SQL Server objects - like tables, views, and

instance objects, including logins - associated with a user’s database.

• DACPAC : A DAC is a self-contained unit of SQL Server database

deployment that enables data-tier developers and DBA’s to package

SQL Server objects into a portable artifact called a DAC package

(OPC zipped file) .

• BACPAC is a related artifact that encapsulates the database schema as

well as the data stored in the database.

Page 52: SQL Server DevOps Jumpstart

SQLPACKAGE.EXE

SqlPackage is a command line utility that automates the following database

development tasks:

• Extract: Creates a database snapshot (.dacpac) file from a live SQL

Server.

• Publish: Incrementally updates a database schema to match the schema

of a source .dacpac file.

• Script: Creates a Transact-SQL incremental update script that updates

the schema of a target to match the schema of a source.

Page 53: SQL Server DevOps Jumpstart

SQLCMD.EXE

SQLCMD lets you enter Transact-SQL statements, system procedures,

and script files :

• At the command prompt.

• SSMS Query editor in SQLCMD mode.

• Windows script file.

• Operating system (Cmd.exe) job step of a SQL Server Agent job.

* SSMS uses the Microsoft.NET FrameworkSqlClient for execution in regular and SQLCMD mode

in Query Editor. When sqlcmd is run from the command line, sqlcmd uses the ODBC driver.

Page 54: SQL Server DevOps Jumpstart

BCP.EXE

• Use bcp.exe bulk copy program to move data from two database

versions.

• Easiest and fastest way to move data.

• Can be automated through the command line.

• Can handle schema changes (query and format file).

Page 57: SQL Server DevOps Jumpstart

QUESTIONS ?