-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2918 from AndrewBulah/md-sa2-30-24
08.DockerCompose
- Loading branch information
Showing
8 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
Andrew_Bulakh/08.DockerCompose/HomeworkAssigment1/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
108
Andrew_Bulakh/08.DockerCompose/HomeworkAssigment2/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
``` |