Commit 352fce6b authored by Chris Kretler's avatar Chris Kretler
Browse files

Pipeline

parent 53c74e42
README.md
.git
node_modules
.gitlab-ci.yml
openshift-artifacts
kubernetes-runner-artifacts
.DS_Store
# Select image from https://hub.docker.com/r/_/php/
image: php:7.2
variables:
# CI_REGISTRY_IMAGE does not need to be specified!!!
CI_REMOTE_REGISTRY: docker-registry.webplatformsunpublished.umich.edu
CI_IMAGE_NAME: my-app
CI_BUILD_REF: latest
before_script:
# Install dependencies
- bash ci/docker_install.sh > /dev/null
# should probably be: build test image, test, build prod image, deploy
stages:
- build
# - test
- tag
- push
test:app:
# This stage builds the application. It will be pushed
# and tested in subsequent steps.
build:
stage: build
script:
- phpunit --configuration phpunit_hello.xml
- docker build -t $CI_IMAGE_NAME .
only:
- pipeline
#test:
# image: $CI_REGISTRY_IMAGE:$CI_BUILD_REF
# services: []
# before_script: []
# stage: test
# script:
# - docker build -t my-app-test -f Dockerfile-test .
# - docker run -it my-app-test
# except:
# - tags
# tag the built image as latest for pushing into OpenShift registry.
tag:
stage: tag
script:
- docker tag $CI_IMAGE_NAME:$CI_BUILD_REF $CI_REMOTE_REGISTRY/chris-sandbox/$CI_IMAGE_NAME:latest
only:
- pipeline
# Master will be released with :latest as the tag
push:
stage: push
script:
- docker login -u registry-access -p $OS_PROD_TOKEN $CI_REMOTE_REGISTRY
- docker push $CI_REMOTE_REGISTRY/chris-sandbox/$CI_IMAGE_NAME:latest
only:
- pipeline
FROM mhart/alpine-node
FROM node:10.12
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
COPY package*.json .
RUN npm install
COPY . /usr/src/app
RUN adduser -D myuser
USER myuser
COPY . .
EXPOSE 5000
CMD [ "npm", "start" ]
CMD [ "npm", "start" ]
\ No newline at end of file
<?php
print("Hello World!");
?>
......@@ -14,13 +14,6 @@ Push/merge to master
- Tag image with `latest`
- Deploy to staging
Tag
- Pull image for SHA (would be nice to re-build if needed for some reason)
- Tag image with new tag
- Deploy to production
Manual deploy from non-master branch to staging
Manual deploy from master branch to production
## Note
......
<?php
print("Hello World");
?>
<?php
function loader($class)
{
$file = $class . '.php';
if (file_exists($file)) {
require $file;
}
}
spl_autoload_register('loader');
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && exit 0
set -xe
# Install git (the php image doesn't have it) which is required by composer
apt-get update -yqq
apt-get install git -yqq
# Install phpunit, the tool that we will use for testing
curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar
chmod +x /usr/local/bin/phpunit
# Install mysql driver
# Here you can install any other extension that you need
docker-php-ext-install pdo_mysql
#oc create is node --lookup-local=true
oc tag docker.io/node:10.12 node:10.12 --reference-policy='local'
oc new-app ssh://git@gitlab.aws.vdc.it.umich.edu/its-web-platforms/k8s-gitlab-sample --source-secret=gitlab-ssh-secret --name=my-app
some change:
git add .
git commit -m 'some change to my app.'
git push
git checkout master
git merge pipeline
\ No newline at end of file
var express = require('express')
var app = express()
app.set('port', (process.env.PORT || 5000))
// Constants
const PORT = 5000;
const HOST = '0.0.0.0';
app.use(express.static(__dirname + '/public'))
app.get('/*', function(req, res){
......@@ -9,6 +12,5 @@ app.get('/*', function(req, res){
res.sendfile(path, {root: './public'});
});
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'))
})
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);
\ No newline at end of file
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
labels:
app: my-app
name: my-app
namespace: chris-sandbox
spec:
replicas: 1
selector:
deploymentconfig: my-app
strategy:
activeDeadlineSeconds: 21600
resources: {}
rollingParams:
intervalSeconds: 1
maxSurge: 25%
maxUnavailable: 25%
timeoutSeconds: 600
updatePeriodSeconds: 1
type: Rolling
template:
metadata:
creationTimestamp: null
labels:
app: my-app
deploymentconfig: my-app
spec:
containers:
- image: docker-registry.default.svc:5000/chris-sandbox/my-app:latest
imagePullPolicy: Always
name: my-app
ports:
- containerPort: 5000
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
test: false
triggers:
- imageChangeParams:
containerNames:
- my-app
from:
kind: ImageStreamTag
name: my-app:latest
namespace: chris-sandbox
type: ImageChange
- type: ConfigChange
\ No newline at end of file
apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
app: my-app
name: my-app
namespace: chris-sandbox
spec:
host: myapp.webplatformsunpublished.umich.edu
to:
kind: Service
name: my-app
weight: 100
wildcardPolicy: None
\ No newline at end of file
apiVersion: v1
kind: Service
metadata:
labels:
app: my-app
name: my-app
namespace: chris-sandbox
spec:
ports:
- port: 5000
protocol: TCP
targetPort: 5000
selector:
deploymentconfig: my-app
sessionAffinity: None
type: ClusterIP
\ No newline at end of file
image: docker:latest
services:
- docker:dind
stages:
- build
- test
- release
- staging
- production
variables:
DOCKER_DRIVER: overlay
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
build:
stage: build
script:
- docker build --pull -t $CI_REGISTRY_IMAGE:$CI_BUILD_REF .
- docker push $CI_REGISTRY_IMAGE:$CI_BUILD_REF
except:
- tags
test1:
image: $CI_REGISTRY_IMAGE:$CI_BUILD_REF
services: []
before_script: []
stage: test
script:
- echo "test1"
except:
- tags
test2:
image: $CI_REGISTRY_IMAGE:$CI_BUILD_REF
services: []
before_script: []
stage: test
script:
- echo "test2"
except:
- tags
# Non-master branches and tags will be released with :<ref_name> as the tag
release-by-name:
stage: release
script:
- docker pull $CI_REGISTRY_IMAGE:$CI_BUILD_REF
- docker tag $CI_REGISTRY_IMAGE:$CI_BUILD_REF $CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME
- docker push $CI_REGISTRY_IMAGE:$CI_BUILD_REF
except:
- master
# Master will be released with :latest as the tag
release-master:
stage: release
script:
- docker pull $CI_REGISTRY_IMAGE:$CI_BUILD_REF
- docker tag $CI_REGISTRY_IMAGE:$CI_BUILD_REF $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:latest
only:
- master
# Depends on CLOUDSDK_CORE_PROJECT, CLOUDSDK_CONTAINER_CLUSTER, and CLOUDSDK_COMPUTE_ZONE being set
.gcloud: &gcloud
- echo $GCLOUD_SERVICE_KEY | base64 --decode -i > ~/gcloud-service-key.json
- gcloud auth activate-service-account --key-file ~/gcloud-service-key.json
- gcloud --quiet container clusters get-credentials $CLOUDSDK_CONTAINER_CLUSTER
.prod_deploy: &prod_deploy
image: google/cloud-sdk
stage: production
environment: production
before_script: *gcloud
script:
- kubectl patch deployment $PRODUCTION_SERVICE_NAME -p '{"spec":{"template":{"spec":{"containers":[{"name":"'"$PRODUCTION_SERVICE_NAME"'","image":"'"$CI_REGISTRY_IMAGE:$CI_BUILD_REF"'"}]}}}}'
.staging_deploy: &staging_deploy
image: google/cloud-sdk
stage: staging
environment: staging
before_script: *gcloud
script:
- kubectl patch deployment $STAGING_SERVICE_NAME -p '{"spec":{"template":{"spec":{"containers":[{"name":"'"$STAGING_SERVICE_NAME"'","image":"'"$CI_REGISTRY_IMAGE:$CI_BUILD_REF"'"}]}}}}'
auto-deploy-master:
<<: *staging_deploy
only:
- master
auto-deploy-tags:
<<: *prod_deploy
only:
- tags
deploy to staging:
<<: *staging_deploy
when: manual
except:
- master
- tags
deploy to production:
<<: *prod_deploy
when: manual
only:
- master
{
"name": "kubernetes-example",
"version": "1.0.0",
"description": "Example app, written in node.js, using Express, built using Docker, deployed using Kubernetes",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"engines": {
"node": "8.11.2"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/gitlab-examples/kubernetes-example.git"
},
"keywords": [
"docker",
"node",
"kubernetes",
"docker"
],
"author": "Mark Pundsack",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/gitlab-examples/kubernetes-example/issues"
},
"homepage": "https://gitlab.com/gitlab-examples/kubernetes-example",
"dependencies": {
"express": "^4.14.0"
}
}
<!DOCTYPE html>
<html>
<head>
<title>GitLab Demo</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<h1>
<img src="logo.svg" /><br />
TITLE
</h1>
<h3>Welcome to GitLab's integrated solution!</h3>
<hr/>
<p>Use issue tracker and merge requests to contribute to project</p>
<p>Use GitLab CI to test, build, and deploy changes</p>
<p>Use GitLab Container Registry to store images</p>
<p>Use Environments to manage deployments</p>
</body>
</html>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="210px" height="210px" viewBox="0 0 210 210" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<!-- Generator: Sketch 3.3.2 (12043) - http://www.bohemiancoding.com/sketch -->
<title>Slice 1</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<g id="logo" sketch:type="MSLayerGroup" transform="translate(0.000000, 10.000000)">
<g id="Page-1" sketch:type="MSShapeGroup">
<g id="Fill-1-+-Group-24">
<g id="Group-24">
<g id="Group">
<path d="M105.0614,193.655 L105.0614,193.655 L143.7014,74.734 L66.4214,74.734 L105.0614,193.655 L105.0614,193.655 Z" id="Fill-4" fill="#E24329"></path>
<path d="M105.0614,193.6548 L66.4214,74.7338 L12.2684,74.7338 L105.0614,193.6548 L105.0614,193.6548 Z" id="Fill-8" fill="#FC6D26"></path>
<path d="M12.2685,74.7341 L12.2685,74.7341 L0.5265,110.8731 C-0.5445,114.1691 0.6285,117.7801 3.4325,119.8171 L105.0615,193.6551 L12.2685,74.7341 L12.2685,74.7341 Z" id="Fill-12" fill="#FCA326"></path>
<path d="M12.2685,74.7342 L66.4215,74.7342 L43.1485,3.1092 C41.9515,-0.5768 36.7375,-0.5758 35.5405,3.1092 L12.2685,74.7342 L12.2685,74.7342 Z" id="Fill-16" fill="#E24329"></path>
<path d="M105.0614,193.6548 L143.7014,74.7338 L197.8544,74.7338 L105.0614,193.6548 L105.0614,193.6548 Z" id="Fill-18" fill="#FC6D26"></path>
<path d="M197.8544,74.7341 L197.8544,74.7341 L209.5964,110.8731 C210.6674,114.1691 209.4944,117.7801 206.6904,119.8171 L105.0614,193.6551 L197.8544,74.7341 L197.8544,74.7341 Z" id="Fill-20" fill="#FCA326"></path>
<path d="M197.8544,74.7342 L143.7014,74.7342 L166.9744,3.1092 C168.1714,-0.5768 173.3854,-0.5758 174.5824,3.1092 L197.8544,74.7342 L197.8544,74.7342 Z" id="Fill-22" fill="#E24329"></path>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment