Skip to content

Commit

Permalink
Feat: Replace serverless with scw cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Flajt committed Jul 13, 2024
1 parent 9de2509 commit fcb82d9
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 13 deletions.
97 changes: 84 additions & 13 deletions .github/workflows/deploy-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
env_name: ${{ steps.branch_check.outputs.env_name }}

build:
env:
GOWORK: off # to enable packaging the modules via go mod vendor
needs: [get_branch]
environment:
name: ${{ needs.get_branch.outputs.env_name }}
Expand All @@ -45,24 +47,93 @@ jobs:
- name: Install all dependencies
run: cd ${{github.workspace}}/scw_secret_wrapper && go get . && cd ${{github.workspace}}/helper && go get . && cd ${{github.workspace}}/sign && go get . && cd ${{github.workspace}}/cronjob && go get . && cd ${{github.workspace}}/has_new_key && go get . && cd ${{github.workspace}}/get_new_key && go get . && cd ${{github.workspace}}/originstamp && go get . && cd ${{github.workspace}}/webhook && go get . && cd ${{github.workspace}}/verify_hash && go get .

- name: Run go work vendor
run: cd ${{github.workspace}} && go work vendor
run: cd ${{github.workspace}}/get_new_key && go mod vendor && cd ${{github.workspace}}/has_new_key && go mod vendor && cd ${{github.workspace}}/sign && go mod vendor && cd ${{github.workspace}}/cronjob && go mod vendor && cd ${{github.workspace}}/webhook && go mod vendor && cd ${{github.workspace}}/verify_hash && go mod vendor

- name: Convert secrets to env vars
uses: Firenza/[email protected]
with:
secrets: ${{ toJSON(secrets) }}

- name: Build zips
run: |
zip -r sign.zip sign
zip -r get_new_key.zip get_new_key
zip -r has_new_key.zip has_new_key
zip -r cronjob.zip cronjob
zip -r webhook.zip webhook
zip -r verify_hash.zip verify_hash
- name: Setup npm
uses: actions/setup-node@v3
- name: Deploy sign
uses: scaleway/action-scw@v0
with:
node-version: '18'

- name: Install serverless
run: npm install -g serverless

- name: Install serverless plugin
run: serverless plugin install --name serverless-scaleway-functions
save-config: true
export-config: false
version: v2.24.0
access-key: ${{ secrets.SCW_ACCESS_KEY }}
secret-key: ${{ secrets.SCW_SECRET_KEY }}
default-project-id: ${{ secrets.SCW_PROJECT_ID }}
default-organization-id: ${{ secrets.SCW_ORGANIZATION_ID }} #TODO: Check if in github secrets
args: function deploy name=sign namespace-id=$SCW_NAMESPACE_ID runtime=go122 zip-file=sign.zip

- name: Deploy get_new_key
uses: scaleway/action-scw@v0
with:
save-config: true
export-config: false
version: v2.24.0
access-key: ${{ secrets.SCW_ACCESS_KEY }}
secret-key: ${{ secrets.SCW_SECRET_KEY }}
default-project-id: ${{ secrets.SCW_PROJECT_ID }}
default-organization-id: ${{ secrets.SCW_ORGANIZATION_ID }} #TODO: Check if in github secrets
args: function deploy name=get_new_key namespace-id=$SCW_NAMESPACE_ID runtime=go122 zip-file=get_new_key.zip

- name: Deploy functins
run: serverless deploy
- name: Deploy has_new_key
uses: scaleway/action-scw@v0
with:
save-config: true
export-config: false
version: v2.24.0
access-key: ${{ secrets.SCW_ACCESS_KEY }}
secret-key: ${{ secrets.SCW_SECRET_KEY }}
default-project-id: ${{ secrets.SCW_PROJECT_ID }}
default-organization-id: ${{ secrets.SCW_ORGANIZATION_ID }} #TODO: Check if in github secrets
args: function deploy name=has_new_key namespace-id=$SCW_NAMESPACE_ID runtime=go122 zip-file=has_new_key.zip


- name: Deploy webhook
uses: scaleway/action-scw@v0
with:
save-config: true
export-config: false
version: v2.24.0
access-key: ${{ secrets.SCW_ACCESS_KEY }}
secret-key: ${{ secrets.SCW_SECRET_KEY }}
default-project-id: ${{ secrets.SCW_PROJECT_ID }}
default-organization-id: ${{ secrets.SCW_ORGANIZATION_ID }} #TODO: Check if in github secrets
args: function deploy name=webhook namespace-id=$SCW_NAMESPACE_ID runtime=go122 zip-file=webhook.zip

- name: Deploy verify_hash
uses: scaleway/action-scw@v0
with:
save-config: true
export-config: false
version: v2.24.0
access-key: ${{ secrets.SCW_ACCESS_KEY }}
secret-key: ${{ secrets.SCW_SECRET_KEY }}
default-project-id: ${{ secrets.SCW_PROJECT_ID }}
default-organization-id: ${{ secrets.SCW_ORGANIZATION_ID }} #TODO: Check if in github secrets
args: function deploy name=verify_hash namespace-id=$SCW_NAMESPACE_ID runtime=go122 zip-file=verify_hash.zip

- name: Deploy cronjob
uses: scaleway/action-scw@v0
with:
save-config: true
export-config: false
version: v2.24.0
access-key: ${{ secrets.SCW_ACCESS_KEY }}
secret-key: ${{ secrets.SCW_SECRET_KEY }}
default-project-id: ${{ secrets.SCW_PROJECT_ID }}
default-organization-id: ${{ secrets.SCW_ORGANIZATION_ID }} #TODO: Check if in github secrets
args: function deploy name=cron-job namespace-id=$SCW_NAMESPACE_ID runtime=go122 zip-file=cronjob.zip
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ MCAPTCHA_SECRET=<your-mcaptcha-secret> # needs to be set if you want to verify w
MCAPTCHA_SITEKEY=<your-mcaptcha-site-key> # needs to be set if you want to verify with the website, in PROD it's an encrypted secret
MCAPTCHA_INSTANCE_URL=<your-mcpatcha-instance-url> # needs to be set if you want to verify w. website
```
#### Env vars per function
- sign: `WEBHOOK_URL` & `ORIGINSTAMP_API_KEY`
- get-new-key: `GOOGLE_ADMIN_SDK_CREDS`
- cron-job: ``
- webhook: `ORIGINSTAMP_API_KEY` & `EMAIL_SECRET`
- verify-hash: `ORIGINSTAMP_API_KEY` & `MCAPTCHA_SECRET` & `MCAPTCHA_SITEKEY` & `MCAPTCHA_INSTANCE_URL`

Note to self:
Currently you need to update the functions secrets and env vars via `scw function function update`

The issue is it's nearly needed everywhere, in every function, in every test folder, everywhere...
So please load it into your terminal enviroment. You can use my script in utils for that: `util/load_env.go`. This should load all env vars into your terminal (tested in VSCode), use the `--path` flag to pass the .env file path.

Expand Down

0 comments on commit fcb82d9

Please sign in to comment.