Skip to content

Commit

Permalink
Merge pull request #2918 from AndrewBulah/md-sa2-30-24
Browse files Browse the repository at this point in the history
08.DockerCompose
  • Loading branch information
pluhin authored Jan 16, 2025
2 parents 91d8058 + 2479c0c commit c8377bb
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Andrew_Bulakh/07.Docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Dockerfile

File app.py
```bash
from flask import Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions Andrew_Bulakh/08.DockerCompose/HomeworkAssigment1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 07.Docker Compose

## Homework Assignment 1: Docker Compose for Application Stacks
docker-compose.yaml
```bash
services:
db:
image: mariadb:latest
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: wordpress
MYSQL_USER: andrew
MYSQL_PASSWORD: 123456
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
volumes:
- wordpress_modules:/var/www/html/modules
- wordpress_profiles:/var/www/html/profiles
- wordpress_themes:/var/www/html/themes
- wordpress_sites:/var/www/html/sites
restart: always
volumes:
db_data:
wordpress_modules:
wordpress_profiles:
wordpress_themes:
wordpress_sites:
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions Andrew_Bulakh/08.DockerCompose/HomeworkAssigment2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
## Homework Assignment 1: Docker build automation (github action)

Dockerfile
```bash
FROM python:3.10-slim AS builder

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY app.py .

FROM python:3.10-slim

COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages

COPY app.py .

EXPOSE 8000

CMD ["python", "app.py"]
```

app.py
```bash
from http.server import BaseHTTPRequestHandler, HTTPServer

class SimpleHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(b"Hello, world!")

def run(server_class=HTTPServer, port=8000):
server_address = ('', port)
httpd = server_class(server_address, SimpleHandler)
print(f'Serving on port {port}')
httpd.serve_forever()

if __name__ == "__main__":
run()
```
requirements.txt
```bash
flask
cython
```
[Workflow](https://github.com/AndrewBulah/DockerCompose1/blob/main/.github/workflows/build-and-publich.yaml)
```bash
name: Build and Push Docker Image

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
id: docker_build
run: |
docker build -t andrewfreak/my_app:${{ github.sha }} -f second/Dockerfile second/
docker push andrewfreak/my_app:${{ github.sha }}

- name: Notify Slack (Success)
uses: slackapi/slack-github-action@v1.22.0
with:
payload: |
{
"text": "Docker image *<https://hub.docker.com/r/andrewfreak/my_app/tags|andrewfreak/my_app:${{ github.sha }}>* is successfully pushed!",
"channel": "C088BKGQ92T"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

notify_failure:
needs: build
if: failure()
runs-on: ubuntu-latest
steps:
- name: Notify Slack (Failure)
uses: slackapi/slack-github-action@v1.22.0
with:
payload: |
{
"text": "Failed to build or push Docker image *<https://hub.docker.com/r/andrewfreak/my_app/tags|andrewfreak/my_app>*.",
"channel": "C088BKGQ92T"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
```

0 comments on commit c8377bb

Please sign in to comment.