Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 531831e84b | |||
| 90bb21e38b | |||
| 2f1a137342 | |||
| adf576fbe1 |
@@ -43,6 +43,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Log in to Container Registry
|
- name: Log in to Container Registry
|
||||||
if: github.event_name != 'pull_request' || github.event.inputs.push == 'true'
|
if: github.event_name != 'pull_request' || github.event.inputs.push == 'true'
|
||||||
|
id: login-ghcr
|
||||||
|
continue-on-error: true
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
@@ -73,7 +75,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
context: ./backend
|
context: ./backend
|
||||||
file: ./backend/Dockerfile
|
file: ./backend/Dockerfile
|
||||||
push: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}
|
# Always build; only push when registry login succeeded
|
||||||
|
push: ${{ (github.event_name != 'pull_request' || github.event.inputs.push == 'true') && steps.login-ghcr.outcome == 'success' }}
|
||||||
tags: ${{ steps.meta-backend.outputs.tags }}
|
tags: ${{ steps.meta-backend.outputs.tags }}
|
||||||
labels: ${{ steps.meta-backend.outputs.labels }}
|
labels: ${{ steps.meta-backend.outputs.labels }}
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
@@ -86,7 +89,7 @@ jobs:
|
|||||||
VERSION=${{ steps.meta-backend.outputs.version }}
|
VERSION=${{ steps.meta-backend.outputs.version }}
|
||||||
|
|
||||||
- name: Run Trivy vulnerability scanner
|
- name: Run Trivy vulnerability scanner
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request' && steps.login-ghcr.outcome == 'success'
|
||||||
uses: aquasecurity/trivy-action@master
|
uses: aquasecurity/trivy-action@master
|
||||||
with:
|
with:
|
||||||
image-ref: ${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }}:${{ steps.meta-backend.outputs.version }}
|
image-ref: ${{ env.REGISTRY }}/${{ env.BACKEND_IMAGE_NAME }}:${{ steps.meta-backend.outputs.version }}
|
||||||
@@ -96,7 +99,7 @@ jobs:
|
|||||||
timeout: '10m'
|
timeout: '10m'
|
||||||
|
|
||||||
- name: Upload Trivy scan results to GitHub Security tab
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request' && steps.login-ghcr.outcome == 'success'
|
||||||
uses: github/codeql-action/upload-sarif@v3
|
uses: github/codeql-action/upload-sarif@v3
|
||||||
with:
|
with:
|
||||||
sarif_file: 'trivy-backend.sarif'
|
sarif_file: 'trivy-backend.sarif'
|
||||||
@@ -120,6 +123,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Log in to Container Registry
|
- name: Log in to Container Registry
|
||||||
if: github.event_name != 'pull_request' || github.event.inputs.push == 'true'
|
if: github.event_name != 'pull_request' || github.event.inputs.push == 'true'
|
||||||
|
id: login-ghcr
|
||||||
|
continue-on-error: true
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
@@ -150,7 +155,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
context: ./frontend
|
context: ./frontend
|
||||||
file: ./frontend/Dockerfile
|
file: ./frontend/Dockerfile
|
||||||
push: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}
|
# Always build; only push when registry login succeeded
|
||||||
|
push: ${{ (github.event_name != 'pull_request' || github.event.inputs.push == 'true') && steps.login-ghcr.outcome == 'success' }}
|
||||||
tags: ${{ steps.meta-frontend.outputs.tags }}
|
tags: ${{ steps.meta-frontend.outputs.tags }}
|
||||||
labels: ${{ steps.meta-frontend.outputs.labels }}
|
labels: ${{ steps.meta-frontend.outputs.labels }}
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
@@ -163,7 +169,7 @@ jobs:
|
|||||||
VERSION=${{ steps.meta-frontend.outputs.version }}
|
VERSION=${{ steps.meta-frontend.outputs.version }}
|
||||||
|
|
||||||
- name: Run Trivy vulnerability scanner
|
- name: Run Trivy vulnerability scanner
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request' && steps.login-ghcr.outcome == 'success'
|
||||||
uses: aquasecurity/trivy-action@master
|
uses: aquasecurity/trivy-action@master
|
||||||
with:
|
with:
|
||||||
image-ref: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:${{ steps.meta-frontend.outputs.version }}
|
image-ref: ${{ env.REGISTRY }}/${{ env.FRONTEND_IMAGE_NAME }}:${{ steps.meta-frontend.outputs.version }}
|
||||||
@@ -173,7 +179,7 @@ jobs:
|
|||||||
timeout: '10m'
|
timeout: '10m'
|
||||||
|
|
||||||
- name: Upload Trivy scan results to GitHub Security tab
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request' && steps.login-ghcr.outcome == 'success'
|
||||||
uses: github/codeql-action/upload-sarif@v3
|
uses: github/codeql-action/upload-sarif@v3
|
||||||
with:
|
with:
|
||||||
sarif_file: 'trivy-frontend.sarif'
|
sarif_file: 'trivy-frontend.sarif'
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "picpeak-backend",
|
"name": "picpeak-backend",
|
||||||
"version": "1.0.119",
|
"version": "1.0.120",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "picpeak-backend",
|
"name": "picpeak-backend",
|
||||||
"version": "1.0.119",
|
"version": "1.0.120",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.850.0",
|
"@aws-sdk/client-s3": "^3.850.0",
|
||||||
"@aws-sdk/lib-storage": "^3.850.0",
|
"@aws-sdk/lib-storage": "^3.850.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "picpeak-backend",
|
"name": "picpeak-backend",
|
||||||
"version": "1.0.119",
|
"version": "1.0.120",
|
||||||
"description": "Backend for PicPeak event photo sharing platform",
|
"description": "Backend for PicPeak event photo sharing platform",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+6
-4
@@ -84,7 +84,7 @@ app.use((req, res, next) => {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
// CORS configuration
|
// CORS configuration (apply only to API routes)
|
||||||
const corsOptions = {
|
const corsOptions = {
|
||||||
origin: function (origin, callback) {
|
origin: function (origin, callback) {
|
||||||
const allowedOrigins = [
|
const allowedOrigins = [
|
||||||
@@ -102,17 +102,19 @@ const corsOptions = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow requests with no origin (like mobile apps or curl)
|
// Allow requests with no origin (like curl) and allow-listed origins
|
||||||
if (!origin || allowedOrigins.indexOf(origin) !== -1) {
|
if (!origin || allowedOrigins.indexOf(origin) !== -1) {
|
||||||
callback(null, true);
|
callback(null, true);
|
||||||
} else {
|
} else {
|
||||||
callback(new Error('Not allowed by CORS'));
|
// Do not error globally; just omit CORS headers on disallowed origins
|
||||||
|
callback(null, false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
credentials: true
|
credentials: true
|
||||||
};
|
};
|
||||||
|
|
||||||
app.use(cors(corsOptions));
|
// Only attach CORS to API endpoints, not static assets
|
||||||
|
app.use('/api', cors(corsOptions));
|
||||||
|
|
||||||
// Initialize rate limiters (they will be created dynamically)
|
// Initialize rate limiters (they will be created dynamically)
|
||||||
let generalRateLimiter;
|
let generalRateLimiter;
|
||||||
|
|||||||
+21
-6
@@ -945,15 +945,30 @@ print_success_message() {
|
|||||||
update_installation() {
|
update_installation() {
|
||||||
print_header "Updating PicPeak"
|
print_header "Updating PicPeak"
|
||||||
|
|
||||||
# Detect existing installation
|
# Prefer explicit native install detection first
|
||||||
if [[ -d "$DOCKER_APP_DIR" ]] || [[ -d "/home/${SUDO_USER:-}/picpeak" ]]; then
|
native_detected=false
|
||||||
INSTALL_METHOD="docker"
|
docker_detected=false
|
||||||
update_docker_installation
|
|
||||||
elif [[ -d "$NATIVE_APP_DIR" ]]; then
|
# Native detection: app/backend exists OR systemd unit present
|
||||||
|
if [[ -d "$NATIVE_APP_DIR/app/backend" ]]; then
|
||||||
|
native_detected=true
|
||||||
|
elif command -v systemctl >/dev/null 2>&1 && systemctl list-unit-files | grep -q '^picpeak-backend.service'; then
|
||||||
|
native_detected=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Docker detection: docker app dir or user home picpeak dir exists
|
||||||
|
if [[ -d "$DOCKER_APP_DIR" ]] || [[ -n "${SUDO_USER:-}" && -d "/home/${SUDO_USER}/picpeak" ]]; then
|
||||||
|
docker_detected=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$native_detected" == true ]]; then
|
||||||
INSTALL_METHOD="native"
|
INSTALL_METHOD="native"
|
||||||
update_native_installation
|
update_native_installation
|
||||||
|
elif [[ "$docker_detected" == true ]]; then
|
||||||
|
INSTALL_METHOD="docker"
|
||||||
|
update_docker_installation
|
||||||
else
|
else
|
||||||
die "No existing PicPeak installation found"
|
die "No existing PicPeak installation found (native dir $NATIVE_APP_DIR/app/backend or docker dir $DOCKER_APP_DIR not present)"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user