Skip to content

Commit e9491a4

Browse files
committed
First project template
1 parent 5f0cb23 commit e9491a4

15 files changed

+1095
-59
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Build docker image
2+
run-name: "Build image for ${{ github.ref_name }} triggered by ${{ github.actor }} for ${{ inputs.environment }}; version: ${{ inputs.version || 'N/A'}}"
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
version:
8+
required: false
9+
type: string
10+
commit_sha:
11+
required: false
12+
type: string
13+
14+
env:
15+
ECR_REPOSITORY: "filecoin-oracle-service"
16+
17+
jobs:
18+
build_and_push:
19+
runs-on: ubuntu-latest
20+
environment: production-fidl
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
with:
26+
ref: ${{ inputs.commit_sha }}
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
with:
31+
driver-opts: network=host
32+
33+
- name: Install deps
34+
run: npm ci
35+
36+
- name: Configure AWS credentials
37+
uses: aws-actions/configure-aws-credentials@v4
38+
with:
39+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
40+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
41+
aws-region: us-east-1
42+
43+
- name: Login to Amazon ECR
44+
uses: aws-actions/amazon-ecr-login@v2
45+
with:
46+
mask-password: "true"
47+
registry-type: public
48+
49+
- name: Docker meta
50+
id: meta
51+
uses: docker/metadata-action@v5
52+
with:
53+
flavor: latest=false
54+
images: public.ecr.aws/f4h6r4m9/${{ env.ECR_REPOSITORY }}
55+
tags: |
56+
type=semver,pattern={{version}},value=${{ inputs.version }},enable=${{inputs.version != ''}}
57+
type=ref,event=branch,pattern={{branch}}
58+
type=ref,event=pr,pattern={{branch}}
59+
60+
- name: Build tag and push Docker image
61+
uses: docker/build-push-action@v6
62+
with:
63+
context: .
64+
push: true
65+
tags: ${{ steps.meta.outputs.tags }}
66+
cache-from: type=gha
67+
cache-to: type=gha,mode=max
68+
github-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/code-check.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Check linter, formatting, tests
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
format_and_lint:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Install deps
15+
run: npm ci
16+
17+
- name: Code format
18+
run: npm run format
19+
20+
- name: Lint code
21+
run: npm run lint
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Manually trigger deploy to staging or production
2+
run-name: "Manually deploy ${{ github.ref_name }} triggered by ${{ github.actor }}; version: ${{ inputs.version }}"
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: "Enter the version number"
9+
required: true
10+
default: "main"
11+
environment:
12+
required: false
13+
description: "Select the environment to deploy to"
14+
type: choice
15+
options:
16+
- production
17+
default: production
18+
19+
permissions:
20+
id-token: write
21+
contents: read
22+
23+
jobs:
24+
trigger-production-deploy:
25+
runs-on: ubuntu-latest
26+
if: ${{ github.ref_name == 'main' && inputs.version != '' && inputs.environment == 'production' }}
27+
steps:
28+
- name: Trigger production deploy
29+
uses: neti-filplus-infra/filplus-deploy-action@main
30+
with:
31+
version: ${{ inputs.version }}
32+
environment: production
33+
ecr-repository: filecoin-oracle-service
34+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_IMAGE_DEPLOYER }}
35+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_IMAGE_DEPLOYER }}
36+
aws-region: us-east-1
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Publish new build
2+
run-name: "Publish new images for ${{ github.ref_name }} triggered by ${{ github.actor }}; version: ${{ inputs.version || 'N/A'}}"
3+
4+
on:
5+
pull_request:
6+
types: [opened, synchronize]
7+
push:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
inputs:
12+
version:
13+
description: "Enter the version number"
14+
required: true
15+
deploy-to-production:
16+
description: "Deploy the new version on production?"
17+
required: false
18+
type: boolean
19+
default: false
20+
21+
permissions:
22+
contents: write
23+
24+
jobs:
25+
code-check:
26+
uses: ./.github/workflows/code-check.yml
27+
28+
bump-version:
29+
runs-on: ubuntu-latest
30+
if: ${{ github.ref_name == 'main' && inputs.version != '' }}
31+
needs:
32+
- code-check
33+
outputs:
34+
commit_sha: ${{ steps.commit-version.outputs.commit_sha }}
35+
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
40+
- name: Install semver
41+
run: npm install semver
42+
43+
- name: Get current version
44+
run: echo "current_version=$(jq -r '.version' package.json)" >> $GITHUB_ENV
45+
46+
- name: Validate and set new version
47+
run: |
48+
new_version="${{ inputs.version }}"
49+
current_version="${{ env.current_version }}"
50+
51+
if npx semver $new_version -r "<=$current_version"; then
52+
echo "Error: New version ($new_version) is lowest or the same as current ($current_version)"
53+
exit 1
54+
fi
55+
56+
- name: Bump version
57+
run: |
58+
npm version ${{ inputs.version }} --no-git-tag-version
59+
60+
- name: Git config
61+
run: |
62+
git config user.name "${GITHUB_ACTOR}"
63+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
64+
65+
- name: Commit version change
66+
id: commit-version
67+
run: |
68+
git commit -am "Update version to ${{ inputs.version }}"
69+
git push origin main
70+
echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
71+
72+
build-and-publish:
73+
needs:
74+
- code-check
75+
- bump-version
76+
if: |
77+
always() &&
78+
!contains(needs.*.result, 'failure') &&
79+
!contains(needs.*.result, 'cancelled')
80+
uses: ./.github/workflows/build-docker-image.yml
81+
with:
82+
version: ${{ inputs.version }}
83+
commit_sha: ${{ github.ref_name == 'main' && inputs.version != '' && needs.bump-version.outputs.commit_sha || '' }}
84+
secrets: inherit
85+
86+
git-tag:
87+
runs-on: ubuntu-latest
88+
needs:
89+
- bump-version
90+
- build-and-publish
91+
if: |
92+
${{ github.ref_name == 'main' && inputs.version != '' }} &&
93+
always() &&
94+
!contains(needs.*.result, 'failure') &&
95+
!contains(needs.*.result, 'cancelled')
96+
steps:
97+
- name: Checkout code
98+
uses: actions/checkout@v4
99+
with:
100+
ref: ${{ needs.bump-version.outputs.commit_sha }}
101+
102+
- name: Create and push tag
103+
run: |
104+
TAG_NAME="v${{ inputs.version }}"
105+
git tag $TAG_NAME
106+
git push origin $TAG_NAME
107+
108+
trigger-production-deploy:
109+
runs-on: ubuntu-latest
110+
needs:
111+
- code-check
112+
- build-and-publish
113+
if: ${{ inputs.version != '' && inputs.deploy-to-production == true }}
114+
environment: production-fidl
115+
steps:
116+
- name: Trigger production deploy
117+
uses: neti-filplus-infra/filplus-deploy-action@main
118+
with:
119+
version: ${{ inputs.version }}
120+
environment: production
121+
ecr-repository: filecoin-oracle-service
122+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_IMAGE_DEPLOYER }}
123+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_IMAGE_DEPLOYER }}
124+
aws-region: us-east-1

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": false,
3+
"trailingComma": "all"
4+
}

Dockerfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
FROM node:24-alpine
1+
FROM node:24-alpine AS build
22
WORKDIR /app
33
COPY package*.json ./
4-
RUN npm ci --production
4+
RUN npm ci
55
COPY . .
6-
CMD ["node", "index.js"]
6+
RUN npm run build
7+
8+
FROM node:24-alpine
9+
WORKDIR /app
10+
COPY package*.json ./
11+
RUN npm ci --omit=dev
12+
COPY --from=build /app/dist ./dist
13+
CMD ["node", "dist/index.js"]

eslint.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import js from "@eslint/js";
2+
import globals from "globals";
3+
import tseslint from "typescript-eslint";
4+
import { defineConfig } from "eslint/config";
5+
6+
export default defineConfig([
7+
{ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"], languageOptions: { globals: globals.browser } },
8+
tseslint.configs.recommended,
9+
]);

0 commit comments

Comments
 (0)