diff --git a/.github/workflows/ci-cd-prod.yaml b/.github/workflows/ci-cd-prod.yaml new file mode 100644 index 0000000..d5bd947 --- /dev/null +++ b/.github/workflows/ci-cd-prod.yaml @@ -0,0 +1,58 @@ +name: stripe-warden CI/CD DEV + +on: + workflow_dispatch: + push: + branches: + - main + +jobs: + build-and-deploy: + env: + PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} + SERVICE: ${{ secrets.GCP_SERVICE }} + REGION: ${{ secrets.GCP_REGION }} + TAG: latest + runs-on: ubuntu-latest + environment: development + steps: + # checkout the repo + - name: "Checkout GitHub Action" + uses: actions/checkout@master + + # Authenticate to Google Cloud + - name: Google Auth + id: auth + uses: "google-github-actions/auth@v2" + with: + credentials_json: "${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}" + + # Authenticate Docker to Google Cloud Artifact Registry + - name: Docker Auth + id: docker-auth + uses: "docker/login-action@v3" + with: + username: _json_key + password: "${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}" + registry: "${{ env.REGION }}-docker.pkg.dev" + + # Build and push the Docker image + - name: Build and Push Container + run: |- + cd packages/stripe-warden && + docker build \ + -f Dockerfile \ + -t "${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}" . + echo "=== IMAGE NAME: ${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}" + docker push "${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}" + + # Deploy to Cloud Run + - name: Deploy to Cloud Run + run: | + gcloud run deploy ${{ env.SERVICE }} \ + --platform=managed \ + --port=3000 \ + --region=${{ env.REGION }} \ + --image="${{ env.REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ env.SERVICE }}:${{ env.TAG }}" \ + --min-instances=0 \ + --max-instances=1 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0e41dcd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM oven/bun:latest as base +WORKDIR /usr/src/app + +COPY . . +RUN bun install + +ENV NODE_ENV=production +ENV PORT=3000 + +RUN chown -R bun:bun ./ + +USER bun +EXPOSE 3000/tcp +CMD [ "bun", "run", "src/index.ts" ] \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index b53376d..7b87cfa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,5 +24,3 @@ app.get("/:id/:filename", async (req: Request, res: Response) => { app.listen(port, () => { console.log(`Server listening on port ${port}`); }); - -// http://localhost:3000/cluvqhyly0007uwfdmg2hn33a/VID_20200103_135115.mp4