Last active
August 22, 2020 00:11
-
-
Save oze4/550aaece1c68ceac815c94dfe81e5b0d to your computer and use it in GitHub Desktop.
Dockerfile / traefik.toml / docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3" | |
services: | |
traefik: | |
image: traefik | |
container_name: traefik | |
restart: "always" | |
command: --api | |
command: --docker | |
ports: | |
- "80:80" | |
- "443:443" | |
labels: | |
- "traefik.enable=true" | |
- "traefik.frontend.rule=Host:monitor.mydomain.com" | |
- "traefik.port=8080" | |
- "traefik.docker.network=traefik-proxy" | |
volumes: | |
- /var/run/docker.sock:/var/run/docker.sock | |
- /srv/traefik/traefik.toml:/traefik.toml | |
- /srv/traefik/acme:/acme | |
# This is the service using the Dockefile | |
service-1: | |
image: ~REDACTED~ | |
container_name: ~REDACTED~ | |
depends_on: | |
- "traefik" | |
restart: "always" | |
labels: | |
- "traefik.enable=true" | |
- "traefik.port=80" | |
- "traefik.frontend.rule=Host:~REDACTED~.mydomain.com" | |
service-2: | |
image: ~REDACTED~ | |
container_name: ~REDACTED~ | |
depends_on: | |
- "traefik" | |
restart: "always" | |
labels: | |
- "traefik.enable=true" | |
- "traefik.port=80" | |
- "traefik.frontend.rule=Host:~REDACTED~.mydomain.com" | |
environment: | |
- MONGO_STRING=~redacted~ | |
- MONGO_AUTH_DB=~redacted~ | |
- SECRET=~redacted~ | |
service-3: | |
image: ~REDACTED~ | |
container_name: ~REDACTED~ | |
depends_on: | |
- "traefik" | |
restart: "always" | |
labels: | |
- "traefik.enable=true" | |
- "traefik.port=80" | |
- "traefik.frontend.rule=Host:~REDACTED~.mydomain.com" | |
environment: | |
- MONGO_STRING=~redacted~ | |
- MONGO_AUTH_DB=~redacted~ | |
- JWT_SIGNATURE=~redacted~ | |
- JWT_ENCRYPTION_KEY=~redacted~ | |
networks: | |
default: | |
external: | |
name: traefik-proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:lts-alpine AS build-stage | |
WORKDIR /app | |
COPY package*.json ./ | |
RUN npm install | |
COPY . . | |
RUN npm run build | |
FROM nginx:stable-alpine | |
COPY --from=build-stage /app/dist /usr/share/nginx/html | |
# this isn't necessary - you don't have to expose a port here | |
EXPOSE 3001 | |
CMD ["nginx", "-g", "daemon off;"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node { | |
def app | |
def dockerhub_container = "user/docker-container" // for dockerhub repo | |
def local_container_name = "docker-container" // name of the image on your docker host | |
def docker_compose_path = "/srv/traefik/docker-compose/" // path to your docker-compose.yml | |
stage('Clone Repository') { | |
checkout scm | |
} | |
stage('Build Image') { | |
app = docker.build("${dockerhub_container}") | |
} | |
stage('Test Image') { | |
app.inside { | |
sh 'echo "Volkswagen Tests passed"' | |
} | |
} | |
stage('Push Image To Docker Hub') { | |
docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') { | |
app.push("${env.BUILD_NUMBER}") | |
app.push("latest") | |
} | |
} | |
stage ('SSH To Docker Host and Deploy') { | |
sshagent(credentials : ['docker-host-creds']) { | |
sh ''' | |
ssh -v user@your-docker-host <<EOF | |
echo "--------------------------------" | |
echo "---- pulling latest image ------" | |
echo "--------------------------------" | |
docker pull '''+dockerhub_container+''':latest | |
echo "--------------------------------" | |
echo "--------------------------------" | |
echo "--- stopping existing image ----" | |
echo "--------------------------------" | |
docker stop '''+local_container_name+''' | |
echo "--------------------------------" | |
echo "--------------------------------" | |
echo "--- removing existing image ----" | |
echo "--------------------------------" | |
docker rm '''+local_container_name+''' | |
echo "--------------------------------" | |
echo "--------------------------------" | |
echo "------ starting new image ------" | |
echo "--------------------------------" | |
cd "'''+docker_compose_path+'''" | |
docker-compose up -d '''+local_container_name+''' | |
echo "--------------------------------" | |
echo "--------------------------------" | |
echo "----------- DONE ---------------" | |
echo "--------------------------------" | |
echo "--------------------------------" | |
EOF | |
''' | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
debug = false | |
logLevel = "ERROR" | |
defaultEntryPoints = ["http", "https"] | |
[web] | |
address = ":8080" | |
[web.auth.basic] | |
users = ["~REDACTED~"] | |
[entryPoints] | |
[entryPoints.http] | |
address = ":80" | |
[entryPoints.http.redirect] | |
entryPoint = "https" | |
[entryPoints.https] | |
address = ":443" | |
[entryPoints.https.tls] | |
[[entryPoints.https.tls.certificates]] | |
certFile = """ | |
-----BEGIN CERTIFICATE----- | |
~REDACTED~ | |
-----END CERTIFICATE----- | |
""" | |
keyFile = """ | |
-----BEGIN PRIVATE KEY----- | |
~REDACTED~ | |
-----END PRIVATE KEY----- | |
""" | |
[retry] | |
[docker] | |
endpoint = "unix:///var/run/docker.sock" | |
domain = "mydomain.com" | |
watch = true | |
exposedByDefault = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment