feat(ci): Migrate CI/CD workflow from GitLab CI to Gitea CI
This commit is contained in:
parent
c931a0459a
commit
1a1ceba76d
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
name: Default (not tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: code.foss.global/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
name: Default (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: code.foss.global/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
pnpm install -g @git.zone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
140
.gitlab-ci.yml
140
.gitlab-ci.yml
@ -1,140 +0,0 @@
|
|||||||
# gitzone ci_default
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: '$CI_BUILD_STAGE'
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- npm install -g @shipzone/npmci
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --production --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
auditDevDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high --only=dev
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testStable:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testBuild:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command tsdoc
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
36
changelog.md
Normal file
36
changelog.md
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-10-26 - 2.2.0 - feat(ci)
|
||||||
|
Migrate CI/CD workflow from GitLab CI to Gitea CI
|
||||||
|
|
||||||
|
- Added new Gitea CI workflows for both non-tag and tag-based pushes
|
||||||
|
- Removed existing GitLab CI configuration
|
||||||
|
|
||||||
|
## 2024-05-29 - 2.1.1 - Updates and minor changes
|
||||||
|
Updates and changes based on minor configuration improvements and organizational shifts.
|
||||||
|
|
||||||
|
- Updated description file.
|
||||||
|
- Updated tsconfig settings.
|
||||||
|
- Updated npmextra.json with new githost configuration.
|
||||||
|
- Shifted to new organizational scheme.
|
||||||
|
|
||||||
|
## 2022-07-30 - 2.1.0 - Core improvements and fixes
|
||||||
|
Minor improvements and important core changes.
|
||||||
|
|
||||||
|
- Removed tslint from the core setup.
|
||||||
|
|
||||||
|
## 2022-07-30 - 2.0.2 - Bucket creation improvement
|
||||||
|
Enhanced file structure management.
|
||||||
|
|
||||||
|
- Improved bucket creation to store locally within the .nogit directory.
|
||||||
|
|
||||||
|
## 2022-04-14 - 2.0.0 to 2.0.1 - Structural updates and fixes
|
||||||
|
This release focused on core updates and structural changes.
|
||||||
|
|
||||||
|
- Reformatted the project structure.
|
||||||
|
- Core updates with minor fixes.
|
||||||
|
|
||||||
|
## 2021-12-20 - 1.0.10 - ESM Transition
|
||||||
|
Breaking changes and minor fixes, transitioning to ES Modules.
|
||||||
|
|
||||||
|
- BREAKING CHANGE: Transitioned core setup to ESM.
|
@ -5,21 +5,27 @@
|
|||||||
"githost": "code.foss.global",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "push.rocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smarts3",
|
"gitrepo": "smarts3",
|
||||||
"description": "Creates an S3 endpoint that maps to a local directory for testing and local development.",
|
"description": "A Node.js TypeScript package to create a local S3 endpoint for simulating AWS S3 operations using mapped local directories for development and testing purposes.",
|
||||||
"npmPackagename": "@push.rocks/smarts3",
|
"npmPackagename": "@push.rocks/smarts3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks",
|
"projectDomain": "push.rocks",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"S3 Mock Server",
|
"S3 Mock Server",
|
||||||
"Local S3",
|
"Local S3",
|
||||||
"S3 Testing",
|
|
||||||
"Node.js",
|
"Node.js",
|
||||||
"TypeScript",
|
"TypeScript",
|
||||||
"Local Development",
|
"Local Development",
|
||||||
"Cloud Storage Simulation",
|
"Testing",
|
||||||
|
"Cloud Storage",
|
||||||
"File Storage",
|
"File Storage",
|
||||||
"AWS S3 Compatibility",
|
"AWS S3 Compatibility",
|
||||||
"Development Tool"
|
"Development Tool",
|
||||||
|
"S3 Endpoint",
|
||||||
|
"S3 Simulation",
|
||||||
|
"Bucket Management",
|
||||||
|
"File Upload",
|
||||||
|
"CI/CD Integration",
|
||||||
|
"Developer Onboarding"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
17004
package-lock.json
generated
17004
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
39
package.json
39
package.json
@ -2,7 +2,7 @@
|
|||||||
"name": "@push.rocks/smarts3",
|
"name": "@push.rocks/smarts3",
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "Creates an S3 endpoint that maps to a local directory for testing and local development.",
|
"description": "A Node.js TypeScript package to create a local S3 endpoint for simulating AWS S3 operations using mapped local directories for development and testing purposes.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@ -10,13 +10,15 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild --web --allowimplicitany)"
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.63",
|
"@git.zone/tsbuild": "^2.1.63",
|
||||||
"@gitzone/tsbundle": "^2.0.6",
|
"@git.zone/tsbundle": "^2.0.6",
|
||||||
"@gitzone/tstest": "^1.0.72",
|
"@git.zone/tsrun": "^1.2.49",
|
||||||
"@pushrocks/tapbundle": "^5.0.4",
|
"@git.zone/tstest": "^1.0.72",
|
||||||
|
"@push.rocks/tapbundle": "^5.0.4",
|
||||||
"@types/node": "^18.6.2"
|
"@types/node": "^18.6.2"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
@ -35,27 +37,36 @@
|
|||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartbucket": "^2.0.2",
|
"@push.rocks/smartbucket": "^2.0.2",
|
||||||
"@pushrocks/smartfile": "^10.0.4",
|
"@push.rocks/smartfile": "^10.0.4",
|
||||||
"@pushrocks/smartpath": "^5.0.5",
|
"@push.rocks/smartpath": "^5.0.5",
|
||||||
"@types/s3rver": "^3.7.0",
|
"@types/s3rver": "^3.7.0",
|
||||||
"s3rver": "^3.7.1"
|
"s3rver": "^3.7.1"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"S3 Mock Server",
|
"S3 Mock Server",
|
||||||
"Local S3",
|
"Local S3",
|
||||||
"S3 Testing",
|
|
||||||
"Node.js",
|
"Node.js",
|
||||||
"TypeScript",
|
"TypeScript",
|
||||||
"Local Development",
|
"Local Development",
|
||||||
"Cloud Storage Simulation",
|
"Testing",
|
||||||
|
"Cloud Storage",
|
||||||
"File Storage",
|
"File Storage",
|
||||||
"AWS S3 Compatibility",
|
"AWS S3 Compatibility",
|
||||||
"Development Tool"
|
"Development Tool",
|
||||||
|
"S3 Endpoint",
|
||||||
|
"S3 Simulation",
|
||||||
|
"Bucket Management",
|
||||||
|
"File Upload",
|
||||||
|
"CI/CD Integration",
|
||||||
|
"Developer Onboarding"
|
||||||
],
|
],
|
||||||
"homepage": "https://code.foss.global/push.rocks/smarts3",
|
"homepage": "https://code.foss.global/push.rocks/smarts3#readme",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://code.foss.global/push.rocks/smarts3.git"
|
"url": "git+https://code.foss.global/push.rocks/smarts3.git"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://code.foss.global/push.rocks/smarts3/issues"
|
||||||
}
|
}
|
||||||
}
|
}
|
4962
pnpm-lock.yaml
generated
4962
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
169
readme.md
169
readme.md
@ -1,85 +1,178 @@
|
|||||||
|
```markdown
|
||||||
# @push.rocks/smarts3
|
# @push.rocks/smarts3
|
||||||
create an s3 endpoint that maps to a local directory
|
|
||||||
|
A Node.js TypeScript package to create a local S3 endpoint for development and testing using mapped local directories, simulating AWS S3.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
To use @push.rocks/smarts3 in your project, you'll need to install it via npm. You can do so by running the following command in your project's root directory:
|
To integrate `@push.rocks/smarts3` with your project, you need to install it via npm. Execute the following command within your project's root directory:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm install @push.rocks/smarts3 --save
|
npm install @push.rocks/smarts3 --save
|
||||||
```
|
```
|
||||||
|
|
||||||
This will add `@push.rocks/smarts3` as a dependency to your project's `package.json` file and download the package into the `node_modules` directory.
|
This command will add `@push.rocks/smarts3` as a dependency in your project's `package.json` file and download the package into the `node_modules` directory.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@push.rocks/smarts3 is designed to make it easy for developers to create an S3 compatible endpoint that maps to a local directory. This can be particularly useful for local development and testing, allowing you to mimic S3's functionality without the need for an actual S3 bucket.
|
### Overview
|
||||||
|
|
||||||
Below, we'll go through how to get started, set up an S3 server, manage buckets, and perform common operations.
|
The `@push.rocks/smarts3` module allows users to create a mock S3 endpoint that maps to a local directory using `s3rver`. This simulation of AWS S3 operations facilitates development and testing by enabling file uploads, bucket creation, and other interactions locally. This local setup is ideal for developers looking to test cloud file storage operations without requiring access to a real AWS S3 instance.
|
||||||
|
|
||||||
### Setting up the S3 Server
|
In this comprehensive guide, we will explore setting up a local S3 server, performing operations like creating buckets and uploading files, and how to effectively integrate this into your development workflow.
|
||||||
|
|
||||||
First, let's see how to set up and start an S3 server instance.
|
### Setting Up the Environment
|
||||||
|
|
||||||
|
To begin any operations, your environment must be configured correctly. Here’s a simple setup procedure:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import * as path from 'path';
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
|
|
||||||
|
async function setupEnvironment() {
|
||||||
|
const packageDir = path.resolve();
|
||||||
|
const nogitDir = path.join(packageDir, './.nogit');
|
||||||
|
const bucketsDir = path.join(nogitDir, 'bucketsDir');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.mkdir(bucketsDir, { recursive: true });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to create buckets directory!', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Environment setup complete.');
|
||||||
|
}
|
||||||
|
|
||||||
|
setupEnvironment().catch(console.error);
|
||||||
|
```
|
||||||
|
|
||||||
|
This script sets up a directory structure required for the `smarts3` server, ensuring that the directories needed for bucket storage exist before starting the server.
|
||||||
|
|
||||||
|
### Starting the S3 Server
|
||||||
|
|
||||||
|
Once your environment is set up, start an instance of the `smarts3` server. This acts as your local mock S3 endpoint:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { Smarts3 } from '@push.rocks/smarts3';
|
import { Smarts3 } from '@push.rocks/smarts3';
|
||||||
|
|
||||||
async function startServer() {
|
async function startServer() {
|
||||||
// Creating and starting the Smarts3 instance
|
|
||||||
const smarts3Instance = await Smarts3.createAndStart({
|
const smarts3Instance = await Smarts3.createAndStart({
|
||||||
port: 3000, // optional, defaults to 3000
|
port: 3000,
|
||||||
cleanSlate: true // optional, if set to true, it will empty the directory on start
|
cleanSlate: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('S3 server is up and running...');
|
console.log('S3 server is up and running at http://localhost:3000');
|
||||||
return smarts3Instance;
|
return smarts3Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
startServer().catch(console.error);
|
startServer().catch(console.error);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Creating a Bucket
|
**Parameters:**
|
||||||
|
- **Port**: Specify the port for the local S3 server. Defaults to `3000`.
|
||||||
|
- **CleanSlate**: If `true`, clears the storage directory each time the server starts, providing a fresh test state.
|
||||||
|
|
||||||
With the server up and running, you can now create buckets.
|
### Creating and Managing Buckets
|
||||||
|
|
||||||
|
With your server running, create buckets for storing files. A bucket in S3 acts similarly to a root directory.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
async function createBucket(smarts3Instance: Smarts3) {
|
async function createBucket(smarts3Instance: Smarts3, bucketName: string) {
|
||||||
// Creating a new bucket
|
const bucket = await smarts3Instance.createBucket(bucketName);
|
||||||
const bucket = await smarts3Instance.createBucket('my-awesome-bucket');
|
|
||||||
console.log(`Bucket created: ${bucket.name}`);
|
console.log(`Bucket created: ${bucket.name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assuming startServer() has been called and smarts3Instance has been received
|
startServer()
|
||||||
createBucket(smarts3Instance).catch(console.error);
|
.then((smarts3Instance) => createBucket(smarts3Instance, 'my-awesome-bucket'))
|
||||||
|
.catch(console.error);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Accessing Buckets and Uploading Files
|
### Uploading and Managing Files
|
||||||
|
|
||||||
To perform actions like uploading files, you will need to work with the underlying `SmartBucket` module. The `SmartBucket` module is part of the @push.rocks ecosystem and integrated into smarts3 for easy bucket and file management.
|
Uploading files to a bucket uses the `SmartBucket` module, part of the `@push.rocks/smartbucket` ecosystem:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { SmartBucket, Bucket } from '@pushrocks/smartbucket';
|
import { SmartBucket } from '@push.rocks/smartbucket';
|
||||||
|
|
||||||
async function uploadFile(smarts3Instance: Smarts3) {
|
async function uploadFile(smarts3Instance: Smarts3, bucketName: string, filePath: string, fileContent: string) {
|
||||||
// Getting the S3 descriptor to configure SmartBucket
|
|
||||||
const s3Descriptor = await smarts3Instance.getS3Descriptor();
|
const s3Descriptor = await smarts3Instance.getS3Descriptor();
|
||||||
|
|
||||||
const smartbucketInstance = new SmartBucket(s3Descriptor);
|
const smartbucketInstance = new SmartBucket(s3Descriptor);
|
||||||
const bucket: Bucket = await smartbucketInstance.getBucket('my-awesome-bucket');
|
const bucket = await smartbucketInstance.getBucket(bucketName);
|
||||||
|
|
||||||
// Now let's upload a file to the bucket
|
await bucket.getBaseDirectory().fastStore(filePath, fileContent);
|
||||||
const baseDirectory = await bucket.getBaseDirectory();
|
console.log(`File "${filePath}" uploaded successfully to bucket "${bucketName}".`);
|
||||||
await baseDirectory.fastStore('hello.txt', 'Hello, world!');
|
|
||||||
|
|
||||||
console.log('File uploaded successfully.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadFile(smarts3Instance).catch(console.error);
|
startServer()
|
||||||
|
.then(async (smarts3Instance) => {
|
||||||
|
await createBucket(smarts3Instance, 'my-awesome-bucket');
|
||||||
|
await uploadFile(smarts3Instance, 'my-awesome-bucket', 'hello.txt', 'Hello, world!');
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Listing Files in a Bucket
|
||||||
|
|
||||||
|
Listing files within a bucket allows you to manage its contents conveniently:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function listFiles(smarts3Instance: Smarts3, bucketName: string) {
|
||||||
|
const s3Descriptor = await smarts3Instance.getS3Descriptor();
|
||||||
|
const smartbucketInstance = new SmartBucket(s3Descriptor);
|
||||||
|
const bucket = await smartbucketInstance.getBucket(bucketName);
|
||||||
|
|
||||||
|
const baseDirectory = await bucket.getBaseDirectory();
|
||||||
|
const files = await baseDirectory.listFiles();
|
||||||
|
|
||||||
|
console.log(`Files in bucket "${bucketName}":`, files);
|
||||||
|
}
|
||||||
|
|
||||||
|
startServer()
|
||||||
|
.then(async (smarts3Instance) => {
|
||||||
|
await createBucket(smarts3Instance, 'my-awesome-bucket');
|
||||||
|
await listFiles(smarts3Instance, 'my-awesome-bucket');
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Deleting a File
|
||||||
|
|
||||||
|
Managing storage efficiently involves deleting files when necessary:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
async function deleteFile(smarts3Instance: Smarts3, bucketName: string, filePath: string) {
|
||||||
|
const s3Descriptor = await smarts3Instance.getS3Descriptor();
|
||||||
|
const smartbucketInstance = new SmartBucket(s3Descriptor);
|
||||||
|
const bucket = await smartbucketInstance.getBucket(bucketName);
|
||||||
|
|
||||||
|
await bucket.getBaseDirectory().fastDelete(filePath);
|
||||||
|
console.log(`File "${filePath}" deleted from bucket "${bucketName}".`);
|
||||||
|
}
|
||||||
|
|
||||||
|
startServer()
|
||||||
|
.then(async (smarts3Instance) => {
|
||||||
|
await createBucket(smarts3Instance, 'my-awesome-bucket');
|
||||||
|
await deleteFile(smarts3Instance, 'my-awesome-bucket', 'hello.txt');
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Scenario Integrations
|
||||||
|
|
||||||
|
#### Development and Testing
|
||||||
|
|
||||||
|
1. **Feature Development:** Use `@push.rocks/smarts3` to simulate file upload endpoints, ensuring your application handles file operations correctly before going live.
|
||||||
|
|
||||||
|
2. **Continuous Integration/Continuous Deployment (CI/CD):** Integrate with CI/CD pipelines to automatically test file interactions.
|
||||||
|
|
||||||
|
3. **Data Migration Testing:** Simulate data migrations between buckets to perfect processes before implementation on actual S3.
|
||||||
|
|
||||||
|
4. **Onboarding New Developers:** Offer new team members hands-on practice with mock setups to improve their understanding without real-world consequences.
|
||||||
|
|
||||||
### Stopping the Server
|
### Stopping the Server
|
||||||
|
|
||||||
Finally, when you are done, you can stop the Smarts3 server as follows:
|
Safely shutting down the server when tasks are complete ensures system resources are managed well:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
async function stopServer(smarts3Instance: Smarts3) {
|
async function stopServer(smarts3Instance: Smarts3) {
|
||||||
@ -87,12 +180,16 @@ async function stopServer(smarts3Instance: Smarts3) {
|
|||||||
console.log('S3 server has been stopped.');
|
console.log('S3 server has been stopped.');
|
||||||
}
|
}
|
||||||
|
|
||||||
stopServer(smarts3Instance).catch(console.error);
|
startServer()
|
||||||
|
.then(async (smarts3Instance) => {
|
||||||
|
await createBucket(smarts3Instance, 'my-awesome-bucket');
|
||||||
|
await stopServer(smarts3Instance);
|
||||||
|
})
|
||||||
|
.catch(console.error);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Complete Integration
|
In this guide, we walked through setting up and fully utilizing the `@push.rocks/smarts3` package for local development and testing. The package simulates AWS S3 operations, reducing dependency on remote services and allowing efficient development iteration cycles. By implementing the practices and scripts shared here, you can ensure a seamless and productive development experience using the local S3 simulation capabilities of `@push.rocks/smarts3`.
|
||||||
|
```
|
||||||
Integrating @push.rocks/smarts3 into your development workflow offers a seamless way to mimic Amazon S3 locally. By creating an S3-compatible endpoint that maps to a local directory, you can develop and test applications that interact with S3 without incurring any cost or requiring internet connectivity. Thanks to its API, @push.rocks/smarts3 makes it easy to programmatically manage your local S3 server, create and delete buckets, and upload or download files, ensuring that your applications can be designed with cloud scalability in mind, right from the start.
|
|
||||||
|
|
||||||
## License and Legal Information
|
## License and Legal Information
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
import * as smartbucket from '@pushrocks/smartbucket';
|
import * as smartbucket from '@push.rocks/smartbucket';
|
||||||
|
|
||||||
export { smartbucket };
|
export { smartbucket };
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
import * as plugins from './plugins.js';
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
import * as smarts3 from '../ts/index.js';
|
import * as smarts3 from '../ts/index.js';
|
||||||
@ -16,7 +16,7 @@ tap.test('should create a smarts3 instance and run it', async (toolsArg) => {
|
|||||||
|
|
||||||
tap.test('should be able to access buckets', async () => {
|
tap.test('should be able to access buckets', async () => {
|
||||||
const smartbucketInstance = new plugins.smartbucket.SmartBucket(
|
const smartbucketInstance = new plugins.smartbucket.SmartBucket(
|
||||||
await testSmarts3Instance.getS3Descriptor()
|
await testSmarts3Instance.getS3Descriptor(),
|
||||||
);
|
);
|
||||||
const bucket = await smartbucketInstance.createBucket('testbucket');
|
const bucket = await smartbucketInstance.createBucket('testbucket');
|
||||||
const baseDirectory = await bucket.getBaseDirectory();
|
const baseDirectory = await bucket.getBaseDirectory();
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smarts3',
|
name: '@push.rocks/smarts3',
|
||||||
version: '2.1.1',
|
version: '2.2.0',
|
||||||
description: 'create an s3 endpoint that maps to a local directory'
|
description: 'A Node.js TypeScript package to create a local S3 endpoint for simulating AWS S3 operations using mapped local directories for development and testing purposes.'
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './smarts3.plugins.js';
|
import * as plugins from './plugins.js';
|
||||||
import * as paths from './paths.js';
|
import * as paths from './paths.js';
|
||||||
|
|
||||||
export interface ISmarts3ContructorOptions {
|
export interface ISmarts3ContructorOptions {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import * as plugins from './smarts3.plugins.js';
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
export const packageDir = plugins.path.join(
|
export const packageDir = plugins.path.join(
|
||||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||||
'../'
|
'../',
|
||||||
);
|
);
|
||||||
export const nogitDir = plugins.path.join(packageDir, './.nogit');
|
export const nogitDir = plugins.path.join(packageDir, './.nogit');
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@ import * as path from 'path';
|
|||||||
export { path };
|
export { path };
|
||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as smartbucket from '@pushrocks/smartbucket';
|
import * as smartbucket from '@push.rocks/smartbucket';
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@push.rocks/smartfile';
|
||||||
import * as smartpath from '@pushrocks/smartpath';
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
|
|
||||||
export { smartbucket, smartfile, smartpath };
|
export { smartbucket, smartfile, smartpath };
|
||||||
|
|
Loading…
Reference in New Issue
Block a user