Skip to content

Commit

Permalink
feat: storage prefix path
Browse files Browse the repository at this point in the history
  • Loading branch information
cybersokari committed Dec 10, 2024
1 parent 8b7e4f8 commit ece2862
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 45 deletions.
3 changes: 0 additions & 3 deletions .dockerignore

This file was deleted.

9 changes: 9 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ jobs:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Nodejs
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
run: |
cd ./worker
npm install && npm run build
- name: Build and push
uses: docker/[email protected]
with:
Expand Down
8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ FROM node:22-alpine AS deps
USER root
RUN apk add openjdk17-jre
RUN npm install -g firebase-tools
RUN npm install -g typescript

FROM deps AS prod
WORKDIR /app

COPY worker/. /app/
RUN npm install --omit=dev && npm run build
RUN npm uninstall -g typescript
## Remove .ts files
RUN rm -rf app
COPY worker/lib ./lib
COPY worker/node_modules ./node_modules

COPY start.sh /
CMD ["/bin/sh", "/start.sh"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
run: |
docker run --rm \
-e STORAGE_BUCKET=my-test-results-bucket \ # Specify your Firebase Storage bucket
-e PREFIX=project-123 \ # A path in your storage bucket (Optional)
-e WEBSITE_ID=my-custom-site-id \ # Use a unique ID for the report website
-e WEBSITE_EXPIRES=3d \ # Set the report expiration (e.g., 3 days)
-e KEEP_HISTORY=true \ # Retain historical test data
Expand Down Expand Up @@ -154,6 +155,7 @@ services:
WEBSITE_ID: your-site-id # Assign an ID to your Allure report website
WEBSITE_EXPIRES: 2d # Duration of availability. 1-30 days
STORAGE_BUCKET: your-storage-bucket # Google Cloud storage bucket
PREFIX: project-123 # A path in your storage bucket (Optional)
KEEP_HISTORY: true # Default is true when STORAGE_BUCKET is provided
KEEP_RESULTS: false # Default is false
WATCH_MODE: true
Expand All @@ -169,6 +171,7 @@ ___
| Variable | Description | Example | Default |
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|---------|
| `STORAGE_BUCKET` | Google Cloud Storage bucket name | project-id.firebasestorage.app | None |
| `PREFIX` | A path in your Storage bucket. Optional. | project-123 | None |
| `WEBSITE_ID` | Unique identifier for hosted reports | test-report-id | None |
| `WEBSITE_EXPIRES` | Expiration duration for reports. Examples: 1h, 2d, 3w | 29d | 7d |
| `KEEP_HISTORY` | Backup `reports/history` directory after report generation. | true | true |
Expand Down
Binary file removed assets/docker-logo.png
Binary file not shown.
Binary file removed assets/firebase-logo.png
Binary file not shown.
13 changes: 12 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
ports:
- "9199:9199"
- "4000:4000"
- "5088:5088"
command: ["firebase", "emulators:start", "--only", "storage,logging", "--project", "fir-demo-project", '--config', "./startfirebase.json"]
restart: unless-stopped
healthcheck:
Expand All @@ -17,19 +18,29 @@ services:
build:
dockerfile: Dockerfile
context: .
develop:
watch:
- action: sync+restart
path: ./worker/lib
target: /app/lib
ignore:
- node_modules/
- action: rebuild
path: package.json
container_name: allure-deployer
env_file: .env.slack
environment:
FIREBASE_STORAGE_EMULATOR_HOST: 127.0.0.1:9199 # Dev mode
STORAGE_BUCKET: "fir-demo-project.appspot.com"
PREFIX: 'project-999'
WEBSITE_ID: 'fir-demo-project'
WEBSITE_EXPIRES: 12h
KEEP_HISTORY: true # Default is true when STORAGE_BUCKET is provided
KEEP_RESULTS: true # Default is false
WATCH_MODE: false
TTL_SECS: 6
volumes:
# - ./worker:/app #Devs only. This overrides the /app dir
# - ./worker:/app #Dev only. This overrides the /app dir
- ${PWD}/gcp-key.json:/credentials/key.json:ro
- /Users/sokari/IdeaProjects/appium/reports/ios/allure-results:/allure-results
cpus: 1
Expand Down
3 changes: 2 additions & 1 deletion worker/app/cloud-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {getAllFilesStream} from "./util";
import counter from "./counter";
import pLimit from "p-limit";

const storageHomeDir = 'allure-results'
const prefix = process.env.PREFIX || undefined
const storageHomeDir = prefix ? `${prefix}/allure-results` : 'allure-results'
/**
* CloudStorage Class
*
Expand Down
4 changes: 3 additions & 1 deletion worker/app/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class Counter {
get filesProcessed(){return this.processed}

startTimer(): void {
this.startTime = Date.now();
if(!this.startTime){
this.startTime = Date.now();
}
}
getElapsedSeconds(): string {
if (!this.startTime) {
Expand Down
6 changes: 4 additions & 2 deletions worker/app/notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ansiEscapes from "ansi-escapes";
import chalk from "chalk";
import credential from "./credential";
import {appLog} from "./util";

type SlackCredentials = {
token: string,
conversationId: string,
Expand All @@ -22,6 +23,9 @@ type SlackCredentials = {
export class Notifier {

private get dashboardUrl() {
if (DEBUG) {
return `http://127.0.0.1:4000/storage/${STORAGE_BUCKET}`
}
return new StringBuilder().append("https://console.firebase.google.com/project")
.append(`/${(credential.projectId)}`)
.append(`/storage/${STORAGE_BUCKET}/files`)
Expand Down Expand Up @@ -178,8 +182,6 @@ export class Notifier {
if (cloudStorage) {
if (keepHistory && keepResults) {
appLog(`KEEP_HISTORY and KEEP_RESULTS enabled`)
} else if (!keepHistory && !keepResults) {
appLog(`KEEP_HISTORY and KEEP_RESULTS disabled`)
} else if (keepHistory) {
appLog(`KEEP_HISTORY enabled`)
} else if (keepResults) {
Expand Down
1 change: 0 additions & 1 deletion worker/app/report-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class ReportBuilder {
)
}
await Promise.all(tasks)
return this
}

}
Expand Down
22 changes: 5 additions & 17 deletions worker/app/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as path from "node:path";
import util from "node:util";

const exec = util.promisify(require('child_process').exec)
import { websiteId} from "./constant";
import {DEBUG, websiteId} from "./constant";
import {StringBuilder} from "./string-builder";
import credential from "./credential";

Expand Down Expand Up @@ -92,10 +92,6 @@ export async function changePermissionsRecursively(dirPath: string, mode: fsSync
* @returns {Promise<string | undefined>} - The URL of the deployed site, if successful
*/
export async function publishToFireBaseHosting(configParentDir: string): Promise<string | null> {
// if (DEBUG) {
// console.warn('DEBUG=true: Skipping live deployment')
// return null
// }
const hosting = {
"hosting": {
"public": ".",
Expand Down Expand Up @@ -136,6 +132,10 @@ export async function publishToFireBaseHosting(configParentDir: string): Promise
builder.append('7d')
}

if (DEBUG) {
appLog('DEBUG mode, skipping live deployment')
return 'http://127.0.0.1:8080/';
}
const {stdout, stderr} = await exec(builder.toString())

if (stderr && !stdout) {
Expand All @@ -157,18 +157,6 @@ export async function publishToFireBaseHosting(configParentDir: string): Promise

}

// async function isSiteAvailable(siteId: string) {
// const builder = new StringBuilder()
// builder.append('firebase hosting:sites:get')
// .append(' ').append(siteId)
// .append(' ').append('--project')
// .append(' ').append(credential.projectId)
// const {stdout, stderr} = await exec(builder.toString())
// if(stderr && !stdout) return false
//
// return stdout.contains(siteId)
// }




Expand Down
5 changes: 3 additions & 2 deletions worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function main(): void {
keepResults && cloudStorage ? cloudStorage.uploadResults() : null
]))[0]

// Print GitHub summary
// Prepare GitHub summary
const githubStepSummary = process.env.GITHUB_STEP_SUMMARY
const notifier = new Notifier()
const notifierPromises : Promise<void>[] = []
Expand All @@ -89,7 +89,7 @@ export function main(): void {
} else {
notifier.printSummaryToConsole({url: url})
}
// Send Slack message
// Prepare Slack message
const token = process.env.SLACK_TOKEN;
const conversationId = process.env.SLACK_CHANNEL_ID;
if (conversationId && token) {
Expand All @@ -98,6 +98,7 @@ export function main(): void {
token: token, url: url
}))
}
// Send notifications async
if(notifierPromises.length > 0){
await Promise.all(notifierPromises)
}
Expand Down
36 changes: 29 additions & 7 deletions worker/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,5 @@
"ts-node-dev": "^2.0.0",
"typescript": "^4.9.0"
},
"overrides": {
"ajv": "^8.17.1",
"whatwg-url": "^14.0.0"
},
"private": true
}

0 comments on commit ece2862

Please sign in to comment.