diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index ac0f9788..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,95 +0,0 @@ -version: 2.1 - -orbs: - aws-ecr: circleci/aws-ecr@8.2.1 - kubernetes: circleci/kubernetes@1.3.1 - helm: circleci/helm@2.0.1 - node: circleci/node@5.2.0 - -jobs: - build: - machine: - image: ubuntu-2204:2024.01.1 - resource_class: large - steps: - - checkout - - node/install: - node-version: "22.3" - - run: - name: Install dependencies - command: | - npm install - - run: - name: Run tests - command: | - npm run test - - run: - name: Build project - command: | - npm run build - - build_docker: - machine: - image: ubuntu-2204:2024.01.1 - resource_class: large - steps: - - checkout - - aws-ecr/build-image: - push-image: false - dockerfile: Dockerfile - path: ./ - build-path: ./ - tag: "$CIRCLE_SHA1,$CIRCLE_TAG" - repo: "simple-staking" - - run: - name: Save Docker image to export it to workspace - command: | - docker save $(docker image ls --format '{{.Repository}}:{{.Tag}}') > /tmp/simple-staking.tar - - persist_to_workspace: - root: /tmp - paths: - - simple-staking.tar - - push_docker: - machine: - image: ubuntu-2204:2024.01.1 - resource_class: large - steps: - - attach_workspace: - at: /tmp - - run: - name: Load Docker image from workspace - command: | - docker load -i /tmp/simple-staking.tar - - aws-ecr/ecr-login: - aws-access-key-id: AWS_ACCESS_KEY_ID - aws-secret-access-key: AWS_SECRET_ACCESS_KEY - region: "$AWS_REGION" - - aws-ecr/push-image: - registry-id: AWS_ECR_REGISTRY_ID - region: "$AWS_REGION" - repo: "simple-staking" - tag: "$CIRCLE_SHA1,$CIRCLE_TAG" - -workflows: - CICD: - jobs: - - build - - build_docker: - filters: - tags: - only: /.*/ - branches: - only: - - dev - - main - - push_docker: - requires: - - build_docker - filters: - tags: - only: /.*/ - branches: - only: - - dev - - main diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..7083d434 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,13 @@ +name: ci + +on: + pull_request: + branches: + - '**' + +jobs: + lint_test: + uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@v0.3.0 + with: + run-build: true + run-unit-tests: true \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 00000000..96ed64c2 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,118 @@ +name: docker_publish + +on: + push: + branches: + - 'main' + - 'dev' + tags: + - '*' + +jobs: + lint_test: + uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@v0.3.0 + with: + run-build: true + run-unit-tests: true + + docker_build: + needs: [lint_test] + runs-on: ubuntu-22.04 + strategy: + matrix: + environment: [devnet, staging, testnet, mainnet-private, mainnet] + environment: ${{ matrix.environment }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + uses: docker/build-push-action@v6 + with: + tags: simple-staking:${{ github.sha }} + outputs: type=docker,dest=/tmp/simple-staking-${{ matrix.environment }}.tar + build-args: | + NEXT_PUBLIC_MEMPOOL_API=${{ vars.NEXT_PUBLIC_MEMPOOL_API }} + NEXT_PUBLIC_API_URL=${{ vars.NEXT_PUBLIC_API_URL }} + NEXT_PUBLIC_NETWORK=${{ vars.NEXT_PUBLIC_NETWORK }} + NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES=${{ vars.NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES }} + + - name: Upload Docker image to workspace + uses: actions/upload-artifact@v4 + with: + name: simple-staking-${{ matrix.environment }} + path: /tmp/simple-staking-${{ matrix.environment }}.tar + + dockerhub_publish: + runs-on: ubuntu-22.04 + strategy: + matrix: + environment: [devnet, staging, testnet, mainnet-private, mainnet] + needs: ["docker_build"] + steps: + - name: Download Docker image from workspace + uses: actions/download-artifact@v4 + with: + name: simple-staking-${{ matrix.environment }} + path: /tmp/ + + - name: Load Docker image + run: docker load -i /tmp/simple-staking-${{ matrix.environment }}.tar + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Push Docker image with SHA + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} + docker push ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} + + - name: Push Docker image with Tag + if: startsWith(github.ref, 'refs/tags/') + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} + docker push ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} + + ecr_publish: + runs-on: ubuntu-22.04 + strategy: + matrix: + environment: [devnet, staging, testnet, mainnet-private, mainnet] + needs: ["docker_build"] + steps: + - name: Download Docker image from workspace + uses: actions/download-artifact@v4 + with: + name: simple-staking-${{ matrix.environment }} + path: /tmp/ + + - name: Load Docker image + run: docker load -i /tmp/simple-staking-${{ matrix.environment }}.tar + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ vars.AWS_ECR_REGION }} + + - name: Login to Amazon ECR Private + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Push Docker image with SHA + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} + docker push ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} + + - name: Push Docker image with Tag + if: startsWith(github.ref, 'refs/tags/') + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} + docker push ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} diff --git a/Dockerfile b/Dockerfile index 08973a98..c13ce121 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,17 +13,20 @@ COPY next.config.mjs . COPY tsconfig.json . COPY tailwind.config.ts . COPY postcss.config.js . -COPY docker-entrypoint.sh . - -# We replace NEXT_PUBLIC_* variables here with placeholders -# as next.js automatically replaces those during building -# Later the docker-entrypoint.sh script finds such variables and replaces them -# with the docker environment variables we have set -RUN NEXT_PUBLIC_MEMPOOL_API=APP_NEXT_PUBLIC_MEMPOOL_API \ - NEXT_PUBLIC_API_URL=APP_NEXT_PUBLIC_API_URL \ - NEXT_PUBLIC_NETWORK=APP_NEXT_PUBLIC_NETWORK \ - NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES=APP_NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES \ - npm run build + +ARG NEXT_PUBLIC_MEMPOOL_API +ENV NEXT_PUBLIC_MEMPOOL_API=${NEXT_PUBLIC_MEMPOOL_API} + +ARG NEXT_PUBLIC_API_URL +ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} + +ARG NEXT_PUBLIC_NETWORK +ENV NEXT_PUBLIC_NETWORK=${NEXT_PUBLIC_NETWORK} + +ARG NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES +ENV NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES=${NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES} + +RUN npm run build # Step 2. Production image, copy all the files and run next FROM node:22-alpine3.19 AS runner @@ -35,7 +38,6 @@ RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs USER nextjs -COPY --from=builder --chown=nextjs:nodejs /app/docker-entrypoint.sh ./docker-entrypoint.sh COPY --from=builder /app/public ./public # Automatically leverage output traces to reduce image size @@ -46,6 +48,5 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static # Uncomment the following line to disable telemetry at run time ENV NEXT_TELEMETRY_DISABLED 1 -ENTRYPOINT ["/app/docker-entrypoint.sh"] CMD ["node", "server.js"] STOPSIGNAL SIGTERM diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh deleted file mode 100755 index f1fc77dd..00000000 --- a/docker-entrypoint.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env sh -set -Ex - -# This method has been inspired by the comment here: -# https://github.com/vercel/next.js/discussions/17641#discussioncomment-339555 -function apply_path { - find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_MEMPOOL_API#$MEMPOOL_API#g" - find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_API_URL#$API_URL#g" - find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_NETWORK#$NETWORK#g" - find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES#$DISPLAY_TESTING_MESSAGES#g" -} - -apply_path -echo "Starting Nextjs" -exec "$@"