Skip to content

Instantly share code, notes, and snippets.

@tieubao
Forked from duythinht/README.MD
Created June 10, 2019 16:36
Show Gist options
  • Save tieubao/dde777757cbbd6a00167eaa43788df27 to your computer and use it in GitHub Desktop.
Save tieubao/dde777757cbbd6a00167eaa43788df27 to your computer and use it in GitHub Desktop.
That was a thing, which I want.
  • Must have Dockerfile inside project, that able to run docker built -t test:1.0.0 ./
  • Image must be expose port as 80
  • Image after build could run directly without any config file, config only accept to inject by environment variables
docker run -e "MYSQL_HOST=127.0.0.1" -e "MYSQL_USERNAME=root" test:1.0.0
  • Must have Jenkins file follow this pattern
pipeline {
    agent any

    environment {
        APP_NAME = 'your-application-frontend'
    }
    stages {
        stage('Dockerize') {
            when {
                branch 'master'
            }
            steps {
                script {
                    docker_image = docker.build("asia.gcr.io/docker-veep/${APP_NAME}", "./")
                }
            }
        }

        stage('Publish Docker') {
            when {
                branch 'master'
            }
            steps {
                script {
                    docker.withRegistry('https://asia.gcr.io', 'gcr:docker-veep') {
                        docker_image.push("${env.BRANCH_NAME}-${env.BUILD_NUMBER}")
                        docker_image.push("latest")
                    }
                }
            }
        }

        stage('Deploy') {
            when {
                branch 'master'
            }
            steps {
                build job: 'dm', parameters: [string(name: 'ENVIRONMENT', value: 'develop'), string(name: 'APP', value: "${APP_NAME}"), string(name: 'TAG', value: "${env.BRANCH_NAME}-${env.BUILD_NUMBER}")]
            }
        }
    }
}

NOTE: change application-frontend to your application name, eg: corperate-frontend, corperate-backend

  • App must have endpoint for check health, typically it should be GET /health, that return status 200 and text is OK
# Dockerile
FROM node:10.11.0 as builder
ADD ./ /app
WORKDIR /app
RUN yarn && yarn build
FROM nginx:1.15.5-alpine
WORKDIR /app/public
COPY --from=builder /app/dist/ /app/public/
COPY _etc/nginx.conf /etc/nginx/conf.d/default.conf
# _etc/nginx.conf
server {
listen 80;
location / {
root /app/public;
}
location /health {
return 200 'OK';
add_header Content-Type text/plain;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment