Skip to content

Commit

Permalink
Merge pull request #2 from Yandex-Practicum/add-docker-cache
Browse files Browse the repository at this point in the history
feat: Optimize CI workflow and Docker configuration

- Added Docker Buildx setup using `docker/setup-buildx-action@v3` in the CI workflow.
- Introduced Docker containers build step with `docker/bake-action@v3` for improved build performance.
- Enhanced backend and frontend test steps to ensure proper execution.
- Added cleanup step to properly shutdown Docker Compose services.
- Optimized layer caching in `Dockerfile.backend` and `Dockerfile.frontend` by copying `package.json` and `package-lock.json` before running `npm install`.
- Changed exposed ports in both Dockerfiles from 5000 to 3000.
- Added `docker-bake.hcl` for defining build targets and cache configuration to utilize GitHub Actions cache.

These changes improve build efficiency, resource management, and maintainability of the CI process and Docker configurations.
  • Loading branch information
shestera authored Jul 5, 2024
2 parents 701843c + edf96fe commit f1f6f13
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

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

- name: Build docker containers
uses: docker/bake-action@v3
with:
load: true

- name: Backend test
run: docker compose run backend-test

- name: Frontend test
run: docker compose run frontend-test
run: docker compose run frontend-test

- name: Cleanup
if: always()
run: docker compose down
6 changes: 4 additions & 2 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ ENV NODE_ENV development

WORKDIR /app

COPY . .
COPY package.json package-lock.json ./

RUN npm install

COPY . .

CMD [ "npm", "run", "dev" ]

EXPOSE 5000
EXPOSE 3000
6 changes: 4 additions & 2 deletions Dockerfile.frontend
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ ENV NODE_ENV development

WORKDIR /app

COPY . .
COPY package.json package-lock.json ./

RUN npm install \
&& npm i -g jest \
&& npx playwright install --with-deps chromium

COPY . .

CMD [ "yarn", "start" ]

EXPOSE 5000
EXPOSE 3000
16 changes: 16 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
target "backend" {
cache-to = [
"type=gha,ignore-error=true,mode=max,scope=backend"
]
cache-from = [
"type=gha,scope=backend"
]
}
target "frontend" {
cache-to = [
"type=gha,ignore-error=true,mode=max,scope=frontend"
]
cache-from = [
"type=gha,scope=frontend"
]
}

0 comments on commit f1f6f13

Please sign in to comment.