File tree 2 files changed +30
-9
lines changed
2 files changed +30
-9
lines changed Original file line number Diff line number Diff line change 33
33
role-session-name : GithubActionsSession
34
34
35
35
- name : Login to Amazon ECR
36
+ id : login-ecr
36
37
uses : aws-actions/amazon-ecr-login@v1
37
38
38
39
- name : Install dependencies
@@ -48,12 +49,17 @@ jobs:
48
49
- name : Build
49
50
run : npm run build
50
51
52
+ - name : Set ECR registry
53
+ run : echo "ECR_REGISTRY=${{ steps.login-ecr.outputs.registry }}" >> $GITHUB_ENV
54
+
51
55
- name : Build, tag, and push image to Amazon ECR
52
56
id : build-image
53
57
env :
54
- ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
58
+ ECR_REGISTRY : ${{ env.ECR_REGISTRY }}
55
59
IMAGE_TAG : ${{ github.sha }}
56
60
run : |
61
+ echo "Using ECR_REGISTRY=$ECR_REGISTRY"
62
+ echo "Using IMAGE_TAG=$IMAGE_TAG"
57
63
docker build --cache-from $ECR_REGISTRY/$ECR_REPOSITORY:latest -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
58
64
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
59
65
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
Original file line number Diff line number Diff line change 1
- # Serve the app with NGINX
2
- FROM nginx:alpine
1
+ # Use a specific version of nginx for better reproducibility
2
+ FROM nginx:1.25.3- alpine
3
3
4
- # Copy the build files from the build folder to /usr/share/nginx/html
5
- COPY build /usr/share/nginx/html
4
+ # Add a non-root user for security
5
+ RUN adduser -D -H -u 1001 nginxuser && \
6
+ chown -R nginxuser:nginxuser /usr/share/nginx/html && \
7
+ chown -R nginxuser:nginxuser /var/cache/nginx && \
8
+ touch /var/run/nginx.pid && \
9
+ chown -R nginxuser:nginxuser /var/run/nginx.pid
6
10
7
- # Replace default nginx.conf with custom configuration
8
- COPY nginx.conf /etc/nginx/conf.d/default.conf
11
+ # Copy files with specific ownership
12
+ COPY --chown=nginxuser:nginxuser build /usr/share/nginx/html
13
+ COPY --chown=nginxuser:nginxuser nginx.conf /etc/nginx/conf.d/default.conf
9
14
10
- # Expose the desired port (default is 80 for NGINX)
15
+ # Set working directory
16
+ WORKDIR /usr/share/nginx/html
17
+
18
+ # Switch to non-root user
19
+ USER nginxuser
20
+
21
+ # Expose port
11
22
EXPOSE 80
12
23
13
- # Start NGINX
24
+ # Use exec form of CMD for better signal handling
14
25
CMD ["nginx" , "-g" , "daemon off;" ]
26
+
27
+ # Add healthcheck
28
+ HEALTHCHECK --interval=30s --timeout=3s \
29
+ CMD wget --quiet --tries=1 --spider http://localhost:80/ || exit 1
You can’t perform that action at this time.
0 commit comments