diff --git a/.github/workflows/github-actions-demo.yaml b/.github/workflows/github-actions-demo.yaml new file mode 100644 index 000000000..5edf29385 --- /dev/null +++ b/.github/workflows/github-actions-demo.yaml @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." \ No newline at end of file diff --git a/.github/workflows/github-actions-lint.yaml b/.github/workflows/github-actions-lint.yaml new file mode 100644 index 000000000..d55d1229f --- /dev/null +++ b/.github/workflows/github-actions-lint.yaml @@ -0,0 +1,38 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." + build: + runs-on: ubuntu-latest + needs: Explore-GitHub-Actions + steps: + - run: echo "Code Build" + lint: + runs-on: ubuntu-latest + needs: Explore-GitHub-Actions + steps: + - run: echo "Code Lint" + unittest: + runs-on: ubuntu-latest + needs: Explore-GitHub-Actions + steps: + - run: echo "Code Unittest" + deploy: + runs-on: ubuntu-latest + needs: [lint, unittest] + steps: + - run: echo "Code Deploy" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2d201615e..17640e734 100644 --- a/.gitignore +++ b/.gitignore @@ -153,6 +153,8 @@ dmypy.json # Cython debug symbols cython_debug/ +vars/credentials.yaml + # PyCharm # JetBrains specific template is maintained in a separate JetBrains.gitignore that can # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..b49163230 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +#Ubuntu 22.04 base image +FROM ubuntu:22.04 + +#Copy the requirements file +COPY requirements.txt . + +#Install python3 +RUN apt-get update && apt-get install -y python3 python3-pip \ + && useradd -m -s /bin/bash nruser \ + && pip install -r requirements.txt \ + && mkdir /app + +#Copy app +COPY --chown=nruser app /app + +#Switch to the non-root user +USER nruser + +#Add work dir +WORKDIR /app + +#Add entrypoint +ENTRYPOINT [ "python3"] + +#Run the app +CMD ["app.py"] \ No newline at end of file diff --git a/docker-playbook.yaml b/docker-playbook.yaml new file mode 100644 index 000000000..fb8d9b764 --- /dev/null +++ b/docker-playbook.yaml @@ -0,0 +1,38 @@ +- hosts: localhost + gather_facts: no + vars: + image_name: fannymalinova/python_app_from_ansible + image_tag: v1.0.1 + listen_port: 5000 + vars_files: + - vars/credentials.yaml + tasks: + - name: Docker login + docker_login: + username: "{{ dockerhub_credentials['username'] }}" + password: "{{ dockerhub_credentials['password'] }}" + - name: Build an image from Dockerfile + docker_image: + build: + path: ./ + name: "{{ image_name }}" + tag: "{{ image_tag }}" + push: yes + source: build + - name: Logout from Docker Hub + docker_login: + username: "{{ dockerhub_credentials['username'] }}" + state: absent + - name: Run a container from this image + docker_container: + name: python_app_from_ansible_container + image: "{{ image_name }}:{{ image_tag }}" + ports: + - "8080:{{ listen_port }}" + env: + PORT: "{{ listen_port | string }}" + + + + + \ No newline at end of file