Skip to content

Commit 4e4a89e

Browse files
committed
Update Dockerfile to improve error handling and optimize package installation
1 parent e486b38 commit 4e4a89e

File tree

2 files changed

+56
-57
lines changed

2 files changed

+56
-57
lines changed

.github/workflows/docker-image.yml

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,82 +2,76 @@ name: docker-markhazletonsample
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
paths-ignore:
77
- README.md
88
- .vscode/**
99
- .gitignore
1010
pull_request:
11-
branches: [ main ]
11+
branches: [main]
1212
paths-ignore:
1313
- README.md
1414
- .vscode/**
1515
- .gitignore
16-
workflow_dispatch:
16+
workflow_dispatch:
1717

1818
jobs:
19-
2019
build:
21-
2220
runs-on: ubuntu-latest
2321

2422
steps:
25-
- name: Checkout
26-
uses: actions/checkout@v4
23+
- name: Checkout
24+
uses: actions/checkout@v4
2725

28-
- name: Set up QEMU
29-
uses: docker/setup-qemu-action@v2
30-
with:
31-
node-version: 16
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
3228

33-
- name: Set up Docker Buildx
34-
uses: docker/setup-buildx-action@v3
35-
with:
36-
node-version: 16
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
3731

38-
- name: Login to DockerHub
39-
uses: docker/login-action@v2
40-
with:
41-
username: ${{ secrets.DOCKERHUB_USERNAME }}
42-
password: ${{ secrets.DOCKERHUB_TOKEN }}
32+
- name: Login to DockerHub
33+
uses: docker/login-action@v3
34+
with:
35+
username: ${{ secrets.DOCKERHUB_USERNAME }}
36+
password: ${{ secrets.DOCKERHUB_TOKEN }}
4337

44-
- name: Lint Dockerfile
45-
run: docker run --rm -i hadolint/hadolint < ./Mwh.Sample.Web/Dockerfile
38+
- name: Lint Dockerfile
39+
run: docker run --rm -i hadolint/hadolint < ./Mwh.Sample.Web/Dockerfile
4640

47-
- name: Cache Docker layers
48-
id: docker-cache
49-
uses: actions/cache@v3
50-
with:
51-
path: /tmp/.buildx-cache
52-
key: ${{ runner.os }}-buildx-${{ github.sha }}-${{ hashFiles('**/Dockerfile', '**/Mwh.Sample.Web/**/*') }}
53-
restore-keys: |
54-
${{ runner.os }}-buildx-
41+
- name: Cache Docker layers
42+
id: docker-cache
43+
uses: actions/cache@v4
44+
with:
45+
path: /tmp/.buildx-cache
46+
key: ${{ runner.os }}-buildx-${{ github.sha }}-${{ hashFiles('**/Dockerfile', '**/Mwh.Sample.Web/**/*') }}
47+
restore-keys: |
48+
${{ runner.os }}-buildx-
5549
56-
- name: Show Docker info
57-
run: docker info
50+
- name: Show Docker info
51+
run: docker info
5852

59-
- name: Show Buildx version
60-
run: docker buildx version
53+
- name: Show Buildx version
54+
run: docker buildx version
6155

62-
- name: Build and push
63-
id: docker_image
64-
uses: docker/build-push-action@v5
65-
with:
66-
context: .
67-
file: ./Mwh.Sample.Web/Dockerfile
68-
push: true
69-
pull: true
70-
tags: |
71-
${{ secrets.DOCKERHUB_USERNAME }}/mwhsampleweb:latest
72-
${{ secrets.DOCKERHUB_USERNAME }}/mwhsampleweb:${{ github.run_number }}
73-
cache-from: type=local,src=/tmp/.buildx-cache
74-
cache-to: type=local,dest=/tmp/.buildx-cache
56+
- name: Build and push
57+
id: docker_image
58+
uses: docker/build-push-action@v5
59+
with:
60+
context: .
61+
file: ./Mwh.Sample.Web/Dockerfile
62+
push: true
63+
pull: true
64+
tags: |
65+
${{ secrets.DOCKERHUB_USERNAME }}/mwhsampleweb:latest
66+
${{ secrets.DOCKERHUB_USERNAME }}/mwhsampleweb:${{ github.run_number }}
67+
cache-from: type=local,src=/tmp/.buildx-cache
68+
cache-to: type=local,dest=/tmp/.buildx-cache
7569

76-
- name: Cleanup
77-
run: |
78-
docker builder prune -f
79-
docker system prune -f
70+
- name: Cleanup
71+
run: |
72+
docker builder prune -f
73+
docker system prune -f
8074
81-
- name: Set Docker Image Output
82-
run: echo "image=${{ secrets.DOCKERHUB_USERNAME }}/mwhsampleweb:latest" >> $GITHUB_ENV
83-
shell: bash
75+
- name: Set Docker Image Output
76+
run: echo "image=${{ secrets.DOCKERHUB_USERNAME }}/mwhsampleweb:latest" >> $GITHUB_ENV
77+
shell: bash

Mwh.Sample.Web/Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ EXPOSE 443
88
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
99
WORKDIR /src
1010

11+
# Set shell options for better error handling
12+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
13+
1114
# Install Node.js and npm
1215
RUN apt-get update && \
13-
apt-get install -y curl && \
16+
apt-get install -y --no-install-recommends curl && \
1417
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
15-
apt-get install -y nodejs && \
16-
npm install -g npm@latest
18+
apt-get install -y --no-install-recommends nodejs && \
19+
npm install -g npm@latest && \
20+
apt-get clean && \
21+
rm -rf /var/lib/apt/lists/*
1722

1823
# Copy the NuGet configuration and project files
1924
COPY ["nuget.config", "."]

0 commit comments

Comments
 (0)