From 3b50c13ca1691e64ae9382ec658216b49477088e Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sat, 28 Dec 2019 21:35:01 +0200 Subject: Initial commit --- .gitlab-ci.yml | 26 ++++++++++++++++++++++++++ Dockerfile | 3 +++ ansible/deploy-playbook.yaml | 20 ++++++++++++++++++++ public/index.html | 9 +++++++++ 4 files changed, 58 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 Dockerfile create mode 100644 ansible/deploy-playbook.yaml create mode 100644 public/index.html 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 @@ + + + + Demo + + + Hello world + + \ No newline at end of file -- cgit v1.3