Добавлены CI кеши #29
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
name: C++ Build and Run (Сборка и запуск проекта) | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
name: Build Docker Image | |
runs-on: ubuntu-latest | |
steps: | |
# 1. Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# 2. Set up Docker Buildx | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
# 3. Cache Docker layers | |
- name: Cache Docker layers | |
id: cache-docker-layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-docker-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-docker- | |
# 4. Build Docker image using Docker Compose | |
- name: Build Docker image with Docker Compose | |
run: | | |
docker compose build bmstu | |
docker compose up bmstu | |
# Save the image as a tarball | |
docker save bmstu_cpp_course-bmstu:latest -o cpp_course_image.tar | |
# 5. Upload Docker image tarball as artifact | |
- name: Upload Docker image tarball | |
uses: actions/upload-artifact@v3 | |
with: | |
name: cpp_course-image | |
path: cpp_course_image.tar | |
# 6. Save Docker layer cache | |
- name: Save Docker layer cache | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: docker-layer-cache | |
path: /tmp/.buildx-cache | |
run-script: | |
name: Run run.sh Script | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
# 1. Download the Docker image tarball artifact | |
- name: Download Docker image tarball | |
uses: actions/download-artifact@v3 | |
with: | |
name: cpp_course-image | |
path: ./artifacts | |
# 2. Load the Docker image into Docker daemon | |
- name: Load Docker image | |
run: | | |
docker load -i ./artifacts/cpp_course_image.tar | |
# 3. Create a Docker network (optional, if needed) | |
#- name: Create Docker network | |
# run: docker network create my-network || echo "Network already exists" | |
# 4. Run the Docker container and execute the script | |
- name: Run run.sh Script inside Docker Container | |
run: | | |
docker run --rm -v ${{ github.workspace }}:/cppcourse bmstu_cpp_course-bmstu:latest bash -c "/cppcourse/docker/runtasks/run.sh" | |
# 5. (Optional) Bring down any Docker Compose services if previously started | |
#- name: Tear Down Docker Compose (if applicable) | |
# run: docker compose down |