|
31 | 31 | description: 'Docker image name (required if docker-enabled)' |
32 | 32 | required: false |
33 | 33 | type: string |
| 34 | + docker-build-args: |
| 35 | + description: 'Docker build arguments (e.g., "ARG1=value1 ARG2=value2")' |
| 36 | + required: false |
| 37 | + type: string |
| 38 | + default: '' |
34 | 39 | secrets: |
35 | 40 | GH_PAT: |
36 | 41 | required: true |
@@ -97,64 +102,27 @@ jobs: |
97 | 102 | echo "Please update the version in package.json before releasing" |
98 | 103 | exit 1 |
99 | 104 |
|
100 | | - - name: Create Dockerfile if not exists |
| 105 | + - name: Check Dockerfile exists |
101 | 106 | if: inputs.docker-enabled && !inputs.dry-run |
102 | 107 | run: | |
103 | 108 | if [ ! -f Dockerfile ]; then |
104 | | - cat > Dockerfile << 'EOF' |
105 | | - # Build stage |
106 | | - FROM node:${{ inputs.node-version }}-alpine AS builder |
107 | | - |
108 | | - WORKDIR /app |
109 | | - |
110 | | - # Copy package files |
111 | | - COPY ${{ inputs.working-directory }}/package*.json ./ |
112 | | - |
113 | | - # Install dependencies |
114 | | - RUN npm ci --only=production |
115 | | - |
116 | | - # Copy application files |
117 | | - COPY ${{ inputs.working-directory }}/ ./ |
118 | | - |
119 | | - # Build the application |
120 | | - RUN npm run build |
121 | | - |
122 | | - # Runtime stage |
123 | | - FROM node:${{ inputs.node-version }}-alpine |
124 | | - |
125 | | - # Install dumb-init for proper signal handling |
126 | | - RUN apk add --no-cache dumb-init |
127 | | - |
128 | | - # Create non-root user |
129 | | - RUN addgroup -g 1001 -S nodejs && \ |
130 | | - adduser -S nodejs -u 1001 |
131 | | - |
132 | | - WORKDIR /app |
133 | | - |
134 | | - # Copy built application from builder |
135 | | - COPY --from=builder --chown=nodejs:nodejs /app ./ |
136 | | - |
137 | | - # Switch to non-root user |
138 | | - USER nodejs |
139 | | - |
140 | | - # Expose port (adjust as needed) |
141 | | - EXPOSE 3000 |
142 | | - |
143 | | - # Use dumb-init to handle signals properly |
144 | | - ENTRYPOINT ["dumb-init", "--"] |
145 | | - |
146 | | - # Start the application |
147 | | - CMD ["npm", "start"] |
148 | | - EOF |
149 | | - echo "Created Dockerfile" |
| 109 | + echo "Error: Dockerfile not found in repository root" |
| 110 | + echo "Please ensure a Dockerfile exists in the repository before enabling Docker builds" |
| 111 | + exit 1 |
150 | 112 | else |
151 | | - echo "Dockerfile already exists" |
| 113 | + echo "Dockerfile found, proceeding with build" |
152 | 114 | fi |
153 | 115 |
|
154 | 116 | - name: Build Docker image |
155 | 117 | if: inputs.docker-enabled && !inputs.dry-run |
156 | 118 | run: | |
157 | | - docker build -t ${{ inputs.docker-image-name }}:${{ steps.get_version.outputs.version }} . |
| 119 | + BUILD_ARGS="" |
| 120 | + if [ -n "${{ inputs.docker-build-args }}" ]; then |
| 121 | + for arg in ${{ inputs.docker-build-args }}; do |
| 122 | + BUILD_ARGS="$BUILD_ARGS --build-arg $arg" |
| 123 | + done |
| 124 | + fi |
| 125 | + docker build $BUILD_ARGS -t ${{ inputs.docker-image-name }}:${{ steps.get_version.outputs.version }} . |
158 | 126 | docker tag ${{ inputs.docker-image-name }}:${{ steps.get_version.outputs.version }} ${{ inputs.docker-image-name }}:latest |
159 | 127 |
|
160 | 128 | - name: Log in to Azure Container Registry |
|
0 commit comments