Skip to content

Commit ccfa7b4

Browse files
authored
Merge pull request #456 from sir-gon/feature/ga-docker
Feature/ga docker
2 parents 03282d6 + 1a98a36 commit ccfa7b4

File tree

4 files changed

+156
-29
lines changed

4 files changed

+156
-29
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ A clear and concise description of what the bug is.
2121

2222
**To Reproduce**
2323
Steps to reproduce the behavior:
24+
2425
1. Go to '...'
2526
2. Click on '....'
2627
3. Scroll down to '....'
@@ -33,8 +34,10 @@ A clear and concise description of what you expected to happen.
3334
If applicable, add screenshots to help explain your problem.
3435

3536
**Desktop (please complete the following information):**
36-
- OS: [e.g. MacOS, Windows, Linux <distribution>]
37-
- Version [e.g. 10]
37+
38+
- OS: [e.g. MacOS, Windows, Linux \<distribution\>]
39+
- Version [e.g. 10]
3840

3941
**Additional context**
40-
Add any other context about the problem here. Consider environment variables, IDE (+ version), framework version, runtime version, command and parameters of execution.
42+
Add any other context about the problem here. Consider environment variables,
43+
IDE (+ version), framework version, runtime version, command and parameters of execution.

.github/workflows/docker-image.yml

Lines changed: 138 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,123 @@ on: # yamllint disable-line rule:truthy
88
pull_request:
99
branches: ["main"]
1010

11+
env:
12+
IMAGE_NAME: algorithm-exercises-js
13+
ARTIFACT_NAME: algorithm-exercises-js_${{ github.sha }}
14+
1115
jobs:
1216

1317
build:
14-
name: "Build & Test in Docker"
18+
name: "Build Docker images"
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: "LINT: Build and push"
27+
uses: docker/build-push-action@v6
28+
with:
29+
context: .
30+
target: lint
31+
outputs: |
32+
type=docker,dest=/tmp/${{ env.ARTIFACT_NAME }}_lint.tar
33+
tags: |
34+
${{ env.IMAGE_NAME }}:lint
35+
- name: "LINT: Upload artifact"
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: ${{ env.ARTIFACT_NAME }}_lint
39+
path: /tmp/${{ env.ARTIFACT_NAME }}_lint.tar
40+
41+
- name: "TEST: Build and push"
42+
uses: docker/build-push-action@v6
43+
with:
44+
context: .
45+
target: testing
46+
outputs: |
47+
type=docker,dest=/tmp/${{ env.ARTIFACT_NAME }}_test.tar
48+
tags: |
49+
${{ env.IMAGE_NAME }}:test
50+
- name: "TEST: Upload artifact"
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: ${{ env.ARTIFACT_NAME }}_test
54+
path: /tmp/${{ env.ARTIFACT_NAME }}_test.tar
55+
56+
- name: "PRODUCTION: Build and push"
57+
uses: docker/build-push-action@v6
58+
with:
59+
context: .
60+
target: production
61+
outputs: |
62+
type=docker,dest=/tmp/${{ env.ARTIFACT_NAME }}_prod.tar
63+
tags: |
64+
${{ env.IMAGE_NAME }}:latest
65+
${{ env.IMAGE_NAME }}:${{ github.sha }}
66+
- name: "PRODUCTION: Upload artifact"
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: ${{ env.ARTIFACT_NAME }}_prod
70+
path: /tmp/${{ env.ARTIFACT_NAME }}_prod.tar
71+
72+
lint:
73+
name: "Run in docker: LINT"
74+
runs-on: ubuntu-latest
75+
needs: build
76+
steps:
77+
- name: Download artifact
78+
uses: actions/download-artifact@v4
79+
with:
80+
name: ${{ env.ARTIFACT_NAME }}_lint
81+
path: /tmp/
1582

83+
- name: Load image
84+
run: |
85+
docker load --input /tmp/${{ env.ARTIFACT_NAME }}_lint.tar
86+
docker image ls -a
87+
88+
- name: Run lint
89+
run: |
90+
docker run --rm ${{ env.IMAGE_NAME }}:lint make lint
91+
92+
test:
93+
name: "Run in docker: TEST"
1694
runs-on: ubuntu-latest
95+
needs: build
96+
steps:
97+
- name: Download artifact
98+
uses: actions/download-artifact@v4
99+
with:
100+
name: ${{ env.ARTIFACT_NAME }}_test
101+
path: /tmp/
102+
103+
- name: Load image
104+
run: |
105+
docker load --input /tmp/${{ env.ARTIFACT_NAME }}_test.tar
106+
docker image ls -a
17107
108+
- name: Run test
109+
run: |
110+
docker run --rm ${{ env.IMAGE_NAME }}:test make test
111+
112+
security:
113+
name: "Snyk Container"
114+
runs-on: ubuntu-latest
115+
needs: build
18116
steps:
19117
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
20-
- name: Build the Docker image
21-
run: make compose/rebuild
22-
- name: Lint in Docker image
23-
run: make compose/lint
24-
- name: Test in Docker image
25-
run: make compose/test
26-
- name: Run in Docker image
27-
run: make compose/run
28-
- name: Tag Docker image
29-
run: >
30-
docker tag
31-
algorithm-exercises-js:latest
32-
algorithm-exercises-js:${{ github.sha }}
118+
- name: Download artifact
119+
uses: actions/download-artifact@v4
120+
with:
121+
name: ${{ env.ARTIFACT_NAME }}_prod
122+
path: /tmp/
123+
124+
- name: Load image
125+
run: |
126+
docker load --input /tmp/${{ env.ARTIFACT_NAME }}_prod.tar
127+
docker image ls -a
33128
34129
- name: Run Snyk to check Docker image for vulnerabilities
35130
# Snyk can be used to break the build when it detects vulnerabilities.
@@ -44,11 +139,33 @@ jobs:
44139
# yamllint enable rule:line-length
45140
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
46141
with:
47-
image: algorithm-exercises-js:latest
142+
image: ${{ env.IMAGE_NAME }}:${{ github.sha }}
48143
args: --file=Dockerfile
49-
# yamllint disable rule:comments-indentation
50-
# - name: Upload result to GitHub Code Scanning
51-
# uses: github/codeql-action/upload-sarif@v2
52-
# with:
53-
# sarif_file: snyk.sarif
54-
# yamllint enable rule:comments-indentation
144+
145+
scan:
146+
name: "Trivy"
147+
runs-on: ubuntu-latest
148+
needs: build
149+
steps:
150+
- name: Download artifact
151+
uses: actions/download-artifact@v4
152+
with:
153+
name: ${{ env.ARTIFACT_NAME }}_prod
154+
path: /tmp/
155+
156+
- name: Load image
157+
run: |
158+
docker load --input /tmp/${{ env.ARTIFACT_NAME }}_prod.tar
159+
docker image ls -a
160+
161+
- name: Run Trivy vulnerability scanner
162+
uses: aquasecurity/[email protected]
163+
with:
164+
image-ref: ${{ env.IMAGE_NAME }}:${{ github.sha }}
165+
format: 'sarif'
166+
output: 'trivy-results.sarif'
167+
168+
- name: Upload Trivy scan results to GitHub Security tab
169+
uses: github/codeql-action/upload-sarif@v3
170+
with:
171+
sarif_file: 'trivy-results.sarif'

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ COPY ./.markdownlint.yaml ${WORKDIR}/
4949
# yamllint conf
5050
COPY ./.yamllint ${WORKDIR}/
5151
COPY ./.yamlignore ${WORKDIR}/
52+
COPY ./.gitignore ${WORKDIR}/
53+
54+
# Dependencies
55+
RUN npm ci --verbose --ignore-scripts
5256

5357
CMD ["make", "lint"]
5458
###############################################################################
@@ -57,12 +61,15 @@ FROM base AS development
5761
ENV WORKDIR=/app
5862
WORKDIR ${WORKDIR}
5963

64+
# Code source
6065
COPY ./src ${WORKDIR}/src
6166
COPY ./package.json ${WORKDIR}/package.json
6267
COPY ./package-lock.json ${WORKDIR}/package-lock.json
6368
COPY ./Makefile ${WORKDIR}/
6469

65-
RUN npm ci --verbose --ignore-scripts
70+
# Dependencies
71+
COPY --from=lint /app/node_modules ${WORKDIR}/node_modules
72+
6673
RUN ls -alh
6774

6875
# CMD []

compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
services:
44
algorithm-exercises-js-test:
5-
image: algorithm-exercises-js:test
5+
image: ${IMAGE_NAME:-algorithm-exercises-js}:test
66
build:
77
context: .
88
target: testing
@@ -14,7 +14,7 @@ services:
1414
profiles: ["testing"]
1515

1616
algorithm-exercises-js-lint:
17-
image: algorithm-exercises-ts:lint
17+
image: ${IMAGE_NAME:-algorithm-exercises-js}:lint
1818
build:
1919
context: .
2020
target: lint
@@ -26,7 +26,7 @@ services:
2626
profiles: ["lint"]
2727

2828
algorithm-exercises-js-dev:
29-
image: algorithm-exercises-js:dev
29+
image: ${IMAGE_NAME:-algorithm-exercises-js}:dev
3030
build:
3131
context: .
3232
target: development
@@ -38,7 +38,7 @@ services:
3838
profiles: ["development"]
3939

4040
algorithm-exercises-js:
41-
image: algorithm-exercises-js:latest
41+
image: ${IMAGE_NAME:-algorithm-exercises-js}:latest
4242
build:
4343
context: .
4444
target: production

0 commit comments

Comments
 (0)