summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@eficode.com>2019-12-28 21:35:01 +0200
committerJan Tuomi <jan.tuomi@eficode.com>2019-12-28 21:35:01 +0200
commit3b50c13ca1691e64ae9382ec658216b49477088e (patch)
treec622c6174ecd073874daac6eda151ec5a64d95de
Initial commit
-rw-r--r--.gitlab-ci.yml26
-rw-r--r--Dockerfile3
-rw-r--r--ansible/deploy-playbook.yaml20
-rw-r--r--public/index.html9
4 files changed, 58 insertions, 0 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..e7805c5
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,26 @@
+stages:
+ - publish
+ - deploy
+
+publish:
+ stage: publish
+ image: docker:stable
+ services:
+ - docker:stable-dind
+ only:
+ - tags
+ script:
+ - docker info
+ - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
+ - IMAGE="$IMAGE_NAME:$CI_COMMIT_TAG"
+ - IMAGE_LATEST="$IMAGE_NAME:latest"
+ - docker build . -f ./Dockerfile -t "$IMAGE"
+ - docker tag "$IMAGE" "$IMAGE_LATEST"
+ - docker push $IMAGE
+ - docker push $IMAGE_LATEST
+
+deploy:
+ stage: deploy
+ image: ansible
+ script:
+ - ansible-playbook -i "$DEPLOY_HOST" ansible/deploy-playbook.yaml --extra-vars "image_name=$IMAGE"
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..eecdc8f
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,3 @@
+FROM nginx:alpine
+
+COPY public /usr/share/nginx/html/
diff --git a/ansible/deploy-playbook.yaml b/ansible/deploy-playbook.yaml
new file mode 100644
index 0000000..3151f50
--- /dev/null
+++ b/ansible/deploy-playbook.yaml
@@ -0,0 +1,20 @@
+---
+- hosts: all
+ become: true
+ vars:
+ container_name: nginx
+ image_name: nginx
+
+ tasks:
+ - name: Pull nginx image
+ docker_image:
+ name: "{{ default_container_image }}"
+ source: pull
+
+ - name: Create nginx container
+ docker_container:
+ name: "{{ container_name }}"
+ image: "{{ image }}"
+ state: started
+ ports:
+ - "80:80"
diff --git a/public/index.html b/public/index.html
new file mode 100644
index 0000000..5c6b1cb
--- /dev/null
+++ b/public/index.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Demo</title>
+ </head>
+ <body>
+ Hello world
+ </body>
+</html> \ No newline at end of file