Skip to content

Commit 0685e62

Browse files
ci(build): align CI, Docker build and Helm deployment
- Update GitHub Action versions for consistency - Configure Docker build to use proper versioning tags - Fix Helm chart to use the correct image repository - Add security improvements to Docker and Helm deployment - Add volume initialization logic for persistent data
1 parent 6aeea18 commit 0685e62

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

.github/workflows/docker-build-publish.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,26 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout repository
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
1717

1818
- name: Set up Docker Buildx
19-
uses: docker/setup-buildx-action@v2
19+
uses: docker/setup-buildx-action@v3
2020

2121
- name: Log in to GitHub Container Registry
22-
uses: docker/login-action@v2
22+
uses: docker/login-action@v3
2323
with:
2424
registry: ghcr.io
2525
username: ${{ github.actor }}
2626
password: ${{ secrets.GITHUB_TOKEN }}
2727

2828
- name: Build and push Docker image
29-
uses: docker/build-push-action@v4
29+
uses: docker/build-push-action@v5
3030
with:
3131
context: .
3232
file: ./Dockerfile
3333
push: true
34-
tags: ghcr.io/offendingcommit/bingo:latest
34+
tags: |
35+
ghcr.io/offendingcommit/bingo:latest
36+
ghcr.io/offendingcommit/bingo:${{ github.sha }}
37+
${{ github.event_name == 'release' && format('ghcr.io/offendingcommit/bingo:{0}', github.ref_name) || '' }}
3538
build-args: BUILD_ENVIRONMENT=production

.github/workflows/helm-chart.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout repository
19-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
2020

2121
- name: Set up Helm
2222
uses: azure/setup-helm@v1
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- name: Checkout repository
34-
uses: actions/checkout@v3
34+
uses: actions/checkout@v4
3535

3636
- name: Set up Helm
3737
uses: azure/setup-helm@v1

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,17 @@ RUN --mount=type=cache,target=$POETRY_CACHE_DIR \
4343
# Copy the rest of the project
4444
COPY . /app
4545

46+
# Create a non-root user and switch to it
47+
RUN adduser --disabled-password --gecos "" appuser && \
48+
chown -R appuser:appuser /app
49+
USER appuser
50+
4651
# Expose port 8080 (if required)
4752
EXPOSE 8080
4853

54+
# Add healthcheck
55+
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
56+
CMD curl -f http://localhost:8080/ || exit 1
57+
4958
# Set the default command to run the application
5059
CMD ["python", "main.py"]

helm/bingo/templates/deployment.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,29 @@ spec:
2727
serviceAccountName: {{ include "bingo.serviceAccountName" . }}
2828
securityContext:
2929
{{- toYaml .Values.podSecurityContext | nindent 8 }}
30+
{{- if .Values.persistence.enabled }}
31+
initContainers:
32+
- name: init-data
33+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
34+
imagePullPolicy: {{ .Values.image.pullPolicy }}
35+
command: ["/bin/sh", "-c"]
36+
args:
37+
- |
38+
# Initialize phrases.txt if it doesn't exist
39+
if [ ! -f /data/phrases/phrases.txt ]; then
40+
cp /app/phrases.txt /data/phrases/phrases.txt
41+
fi
42+
# Initialize static files if directory is empty
43+
if [ ! -d /data/static ] || [ -z "$(ls -A /data/static)" ]; then
44+
mkdir -p /data/static
45+
cp -r /app/static/* /data/static/
46+
fi
47+
volumeMounts:
48+
- name: phrases-volume
49+
mountPath: /data/phrases
50+
- name: static-volume
51+
mountPath: /data/static
52+
{{- end }}
3053
containers:
3154
- name: {{ .Chart.Name }}
3255
securityContext:

helm/bingo/values.yaml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
replicaCount: 1
22

33
image:
4-
repository: bingo
4+
repository: ghcr.io/offendingcommit/bingo
55
pullPolicy: IfNotPresent
66
tag: "latest"
77

8-
imagePullSecrets: []
8+
imagePullSecrets:
9+
- name: ghcr-pull-secret
910
nameOverride: ""
1011
fullnameOverride: ""
1112

@@ -16,9 +17,19 @@ serviceAccount:
1617

1718
podAnnotations: {}
1819

19-
podSecurityContext: {}
20+
podSecurityContext:
21+
runAsNonRoot: true
22+
runAsUser: 1000
23+
runAsGroup: 1000
24+
fsGroup: 1000
2025

21-
securityContext: {}
26+
securityContext:
27+
allowPrivilegeEscalation: false
28+
runAsNonRoot: true
29+
runAsUser: 1000
30+
capabilities:
31+
drop:
32+
- ALL
2233

2334
service:
2435
type: ClusterIP

0 commit comments

Comments
 (0)