Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/learn-github-actions.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
53 changes: 53 additions & 0 deletions M1-3-Ansible/build-and-run.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
20 changes: 20 additions & 0 deletions M1-3-Ansible/pull-and-start.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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"