From c68342f249dfee0c6ab304899c5fee4e587e0b06 Mon Sep 17 00:00:00 2001 From: shaver007 Date: Tue, 4 Nov 2025 21:57:08 +0200 Subject: [PATCH 1/3] chore: Create ansible playbook.yml --- M1-3-Ansible/playbook.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 M1-3-Ansible/playbook.yml diff --git a/M1-3-Ansible/playbook.yml b/M1-3-Ansible/playbook.yml new file mode 100644 index 000000000..d282fcdea --- /dev/null +++ b/M1-3-Ansible/playbook.yml @@ -0,0 +1,20 @@ +--- +- name: Deploy Docker image + hosts: localhost + vars: + image_name: devops-programme + image_tag: v1 + listen_port: 3000 + tasks: + - name: Pull Docker Image + docker_image: + name: "{{ image_name }}" + source: pull + tag: "{{ image_tag }}" + - name: Start Docker container + docker_container: + name: "{{ image_name }}" + image: "{{ image_name }}" + ports: + - "{{ listen_port | int }}:{{ listen_port | int }}" + state: started \ No newline at end of file From a0b9c994d7c0fa5a9634fd0f7345167e12303178 Mon Sep 17 00:00:00 2001 From: shaver007 Date: Sun, 9 Nov 2025 21:37:05 +0200 Subject: [PATCH 2/3] chore: add build playbook --- M1-3-Ansible/build-and-run.yml | 53 +++++++++++++++++++ .../{playbook.yml => pull-and-start.yml} | 0 2 files changed, 53 insertions(+) create mode 100644 M1-3-Ansible/build-and-run.yml rename M1-3-Ansible/{playbook.yml => pull-and-start.yml} (100%) diff --git a/M1-3-Ansible/build-and-run.yml b/M1-3-Ansible/build-and-run.yml new file mode 100644 index 000000000..c220bdc44 --- /dev/null +++ b/M1-3-Ansible/build-and-run.yml @@ -0,0 +1,53 @@ +--- +- name: Build/push/run locally + hosts: localhost + connection: local + gather_facts: false + + vars: + image_name: devops-programme + image_tag: v2 + container_name: devops-programme-container + container_port: 3000 + listen_port: 3000 + app_dir: "{{ (playbook_dir + '/..') | realpath }}" + dockerfile_relpath: "Dockerfile" + + tasks: + + - name: Compose image ref and Dockerfile absolute path + ansible.builtin.set_fact: + registry_image: "localhost:5000/{{ image_name }}:{{ image_tag }}" + dockerfile_fullpath: "{{ app_dir }}/{{ dockerfile_relpath }}" + + - name: Verify Dockerfile exists at repo root + ansible.builtin.stat: + path: "{{ dockerfile_fullpath }}" + register: dockerfile_stat + + - name: Fail if Dockerfile is missing + ansible.builtin.fail: + msg: "Dockerfile not found at {{ dockerfile_fullpath }}. Check app_dir/dockerfile_relpath." + when: not dockerfile_stat.stat.exists + + - name: Build image from repo root + community.docker.docker_image: + name: "{{ registry_image }}" + source: build + build: + path: "{{ app_dir }}" + dockerfile: "{{ dockerfile_relpath }}" + pull: true + push: false + + - name: Run (or update) container from local registry + community.docker.docker_container: + name: "{{ container_name }}" + image: "{{ registry_image }}" + state: started + recreate: true + restart_policy: unless-stopped + published_ports: + - "{{ listen_port | int }}:{{ container_port | int }}" + env: + PORT: "{{ listen_port | string }}" diff --git a/M1-3-Ansible/playbook.yml b/M1-3-Ansible/pull-and-start.yml similarity index 100% rename from M1-3-Ansible/playbook.yml rename to M1-3-Ansible/pull-and-start.yml From 8c7722d47aa6292cc80aa1d8703cfa0c2f74c306 Mon Sep 17 00:00:00 2001 From: shaver007 Date: Tue, 18 Nov 2025 17:49:27 +0200 Subject: [PATCH 3/3] ci: add github workflow learn-github-actions --- .github/workflows/learn-github-actions.yml | 13 +++++++++++++ Dockerfile | 19 +++++++++++++++++++ requirements.txt | 5 +++++ 3 files changed, 37 insertions(+) create mode 100644 .github/workflows/learn-github-actions.yml create mode 100644 Dockerfile create mode 100644 requirements.txt diff --git a/.github/workflows/learn-github-actions.yml b/.github/workflows/learn-github-actions.yml new file mode 100644 index 000000000..fa42c6d2e --- /dev/null +++ b/.github/workflows/learn-github-actions.yml @@ -0,0 +1,13 @@ +name: learn-github-actions +run-name: ${{ github.actor }} is learning GitHub Actions +on: [push] +jobs: + check-bats-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v4 + with: + node-version: '20' + - run: npm install -g bats + - run: bats -v \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..4e20cfb54 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM ubuntu:22.04 + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + python3 python3-pip \ + && rm -rf /var/lib/apt/lists/* + +COPY requirements.txt /tmp/requirements.txt +RUN pip install --upgrade pip \ + && pip install --no-cache-dir -r /tmp/requirements.txt + +COPY /app /app +WORKDIR /app + +RUN useradd appuser \ + && chown -R appuser:appuser /app +USER appuser + +CMD ["python3", "app.py"] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..134fc824f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +flask==3.0.0 ; python_version >= "3.10" and python_version < "4.0" +itsdangerous==2.1.2 ; python_version >= "3.10" and python_version < "4.0" +jinja2==3.1.2 ; python_version >= "3.10" and python_version < "4.0" +markupsafe==2.1.3 ; python_version >= "3.10" and python_version < "4.0" +werkzeug==3.0.0 ; python_version >= "3.10" and python_version < "4.0" \ No newline at end of file