Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add instructions to readme about running locally #6

Open
cjavilla-stripe opened this issue Jan 22, 2021 · 9 comments
Open

add instructions to readme about running locally #6

cjavilla-stripe opened this issue Jan 22, 2021 · 9 comments

Comments

@cjavilla-stripe
Copy link
Contributor

Let's add some steps for getting docker running locally in the readme.md

@cjavilla-stripe
Copy link
Contributor Author

I started to get it working with act and that is now approved for internal use. I think we just need to set the token somehow.

@cjavilla-stripe
Copy link
Contributor Author

~/samples/checkout-one-time-payments master
❯ act
[CI for stripe-samples/checkout-one-time-payments/test] 🚀  Start image=node:12.6-buster-slim
[CI for stripe-samples/checkout-one-time-payments/test]   🐳  docker run image=node:12.6-buster-slim entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[CI for stripe-samples/checkout-one-time-payments/test]   🐳  docker cp src=/Users/cjavilla/samples/checkout-one-time-payments/. dst=/github/workspace
[CI for stripe-samples/checkout-one-time-payments/test] ⭐  Run actions/checkout@v2
[CI for stripe-samples/checkout-one-time-payments/test]   ✅  Success - actions/checkout@v2
[CI for stripe-samples/checkout-one-time-payments/test] ⭐  Run actions/checkout@v2
[CI for stripe-samples/checkout-one-time-payments/test]   ☁  git clone 'https://github.com/actions/checkout' # ref=v2
[CI for stripe-samples/checkout-one-time-payments/test]   🐳  docker cp src=/Users/cjavilla/.cache/act/actions-checkout@v2 dst=/actions/
[CI for stripe-samples/checkout-one-time-payments/test]   ❓  ::save-state name=isPost,::true
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::GITHUB_WORKSPACE = '/github/workspace'
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::qualified repository = 'stripe-samples/sample-ci'
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::ref = ''
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::commit = 'undefined'
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::clean = true
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::fetch depth = 1
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::lfs = false
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::submodules = false
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::recursive submodules = false
[CI for stripe-samples/checkout-one-time-payments/test]   ❗  ::error::Input required and not supplied: token
[CI for stripe-samples/checkout-one-time-payments/test]   ❌  Failure - actions/checkout@v2
Error: exit with `FAILURE`: 1

@hibariya
Copy link
Collaborator

That's great! By running the following steps, I could run the same tests as CI on my local machine. Could you try this on checkout-single-subscription?

(replace XXX with proper values)

cp -rp path/to/sample-ci .

export STRIPE_PUBLISHABLE_KEY=XXX
export STRIPE_SECRET_KEY=XXX
export BASIC=XXX # price id for basic plan (you can find the value in ci.yml)
export PREMIUM=XXX # price id for premium plan (ditto)

source sample-ci/helpers.sh
install_docker_compose_settings
export STRIPE_WEBHOOK_SECRET=$(retrieve_webhook_secret)

# NOTE: The required variables here depend on the sample repository.
#       STRIPE_PUBLISHABLE_KEY, STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, and STATIC_DIR will be set via docker-compose.yml
#       Add additional variables here that .env.sample suggests.
cat <<EOF >> .env
DOMAIN=http://web:4242
BASIC_PRICE_ID=${BASIC}
PRO_PRICE_ID=${PREMIUM}
EOF

configure_docker_compose_for_integration . ruby ../../client
docker-compose up -d && wait_web_server
docker-compose exec -T runner bundle exec rspec spec/server_spec.rb

If it works, I believe the other repositories can be tested locally in similar ways.

@hibariya
Copy link
Collaborator

I started to get it working with act and that is now approved for internal use. I think we just need to set the token somehow.

Oh, I missed the comments. I'll check it later 🙏

@hibariya
Copy link
Collaborator

I think I could successfully run CI for checkout-one-time-payments with act. As you mentioned, it is necessary to pass the secret variables to act. We can do that by creating .secret file on the root of the repository like below (replace the values with proper values):

GITHUB_TOKEN=(GitHub Personal Access Token; https://github.com/settings/tokens)
TEST_STRIPE_PUBLISHABLE_KEY=XXX
TEST_STRIPE_SECRET_KEY=XXX

Additionally, I had to setup Docker and Docker Compose for act because the default environment that act provides does not have docker. Also, it was necessary to remove sudo from the steps. Eventually, I've changed the ci.yml on my local machine like this:

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 98c087e..307d299 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -17,12 +17,34 @@ jobs:
 
       - name: Install gettext for envsubst
         run: |
-          sudo apt install gettext-base
+          apt update
+          apt install gettext-base
 
       - name: Install jq
         run: |
-          sudo curl -o /usr/bin/jq -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
-          sudo chmod +x /usr/bin/jq
+          curl -o /usr/bin/jq -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
+          chmod +x /usr/bin/jq
+
+      - name: Setup docker for act
+        run: |
+          # SEE: https://docs.docker.com/compose/install/ and https://docs.docker.com/engine/install/debian/
+          apt-get update
+          apt-get install -y \
+              apt-transport-https \
+              ca-certificates \
+              curl \
+              gnupg-agent \
+              software-properties-common
+          curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
+          add-apt-repository \
+           "deb [arch=amd64] https://download.docker.com/linux/debian \
+           $(lsb_release -cs) \
+           stable"
+          apt-get update
+          apt-get install -y docker-ce docker-ce-cli containerd.io
+
+          curl -L "https://github.com/docker/compose/releases/download/1.28.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
+          chmod +x /usr/local/bin/docker-compose
 
       - name: Run tests
         run: |

Here are the complete contents of the updated ci.yml for act.

name: CI for stripe-samples/checkout-one-time-payments
on:
  push:
    branches:
      - master

jobs:
  test:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2

      - uses: actions/checkout@v2
        with:
          repository: 'stripe-samples/sample-ci'
          path: 'sample-ci'

      - name: Install gettext for envsubst
        run: |
          apt update
          apt install gettext-base

      - name: Install jq
        run: |
          curl -o /usr/bin/jq -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
          chmod +x /usr/bin/jq

      - name: Setup docker for act
        run: |
          # SEE: https://docs.docker.com/compose/install/ and https://docs.docker.com/engine/install/debian/
          apt-get update
          apt-get install -y \
              apt-transport-https \
              ca-certificates \
              curl \
              gnupg-agent \
              software-properties-common
          curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
          add-apt-repository \
           "deb [arch=amd64] https://download.docker.com/linux/debian \
           $(lsb_release -cs) \
           stable"
          apt-get update
          apt-get install -y docker-ce docker-ce-cli containerd.io

          curl -L "https://github.com/docker/compose/releases/download/1.28.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
          chmod +x /usr/local/bin/docker-compose

      - name: Run tests
        run: |
          source sample-ci/helpers.sh

          install_docker_compose_settings
          export STRIPE_WEBHOOK_SECRET=$(retrieve_webhook_secret)
          cat <<EOF >> .env
          DOMAIN=http://web:4242
          PRICE=${PRICE}
          PAYMENT_METHOD_TYPES="card,ideal"
          EOF

          for lang in $(cat .cli.json | server_langs_for_integration main)
          do
            [ "$lang" = "php" ] && continue

            configure_docker_compose_for_integration . "$lang" ../../client/html

            docker-compose up -d && wait_web_server
            docker-compose exec -T runner bundle exec rspec spec/client_and_server_spec.rb
          done
        env:
          STRIPE_PUBLISHABLE_KEY: ${{ secrets.TEST_STRIPE_PUBLISHABLE_KEY }}
          STRIPE_SECRET_KEY: ${{ secrets.TEST_STRIPE_SECRET_KEY }}
          PRICE: price_1ICW8OCWW2eVYDoPXTu7iRvB

      - name: Collect debug information
        if: ${{ failure() }}
        run: |
          cat docker-compose.yml
          docker-compose ps -a
          docker-compose logs web
        env:
          STRIPE_PUBLISHABLE_KEY: ${{ secrets.TEST_STRIPE_PUBLISHABLE_KEY }}
          STRIPE_SECRET_KEY: ${{ secrets.TEST_STRIPE_SECRET_KEY }}
          PREMIUM: price_1HXyXwCWW2eVYDoPnnTQ02VO
          BASIC: price_1HXyVBCWW2eVYDoPtXcEdXfw

It's great if we can make the ci.yml compatible with both GitHub Actions and act.

@cjavilla-stripe
Copy link
Contributor Author

This is still failing for me with both act and the steps above :)

~/samples/checkout-one-time-payments master*
❯ act
[CI for stripe-samples/checkout-one-time-payments/test] 🚀  Start image=node:12.6-buster-slim
[CI for stripe-samples/checkout-one-time-payments/test]   🐳  docker run image=node:12.6-buster-slim entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[CI for stripe-samples/checkout-one-time-payments/test]   🐳  docker cp src=/Users/cjavilla/samples/checkout-one-time-payments/. dst=/github/workspace
[CI for stripe-samples/checkout-one-time-payments/test] ⭐  Run actions/checkout@v2
[CI for stripe-samples/checkout-one-time-payments/test]   ✅  Success - actions/checkout@v2
[CI for stripe-samples/checkout-one-time-payments/test] ⭐  Run actions/checkout@v2
[CI for stripe-samples/checkout-one-time-payments/test]   ☁  git clone 'https://github.com/actions/checkout' # ref=v2
[CI for stripe-samples/checkout-one-time-payments/test]   🐳  docker cp src=/Users/cjavilla/.cache/act/actions-checkout@v2 dst=/actions/
[CI for stripe-samples/checkout-one-time-payments/test]   ❓  ::save-state name=isPost,::true
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::GITHUB_WORKSPACE = '/github/workspace'
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::qualified repository = 'stripe-samples/sample-ci'
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::ref = ''
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::commit = 'undefined'
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::clean = true
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::fetch depth = 1
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::lfs = false
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::submodules = false
[CI for stripe-samples/checkout-one-time-payments/test]   💬  ::debug::recursive submodules = false
[CI for stripe-samples/checkout-one-time-payments/test]   ❗  ::error::Input required and not supplied: token
[CI for stripe-samples/checkout-one-time-payments/test]   ❌  Failure - actions/checkout@v2
Error: exit with `FAILURE`: 1

~/samples/checkout-one-time-payments master*
❯ cat .secret
GITHUB_TOKEN=<my key>
TEST_STRIPE_PUBLISHABLE_KEY=pk_test_...
TEST_STRIPE_SECRET_KEY=sk_test_...

@hibariya
Copy link
Collaborator

hibariya commented Feb 8, 2021

Renaming .secret to .secrets helps?

@cjavilla-stripe
Copy link
Contributor Author

cjavilla-stripe commented Feb 24, 2021

If you have the latest version of act, and a .secrets file in the root of the sample project, this should work to run the github actions: act

For 0.2.18 you might need to pass act --secrets-file .secrets for newer versions you can just call act and it should work. (brew install act)

Selecting Medium for the docker image size seems fine.

Note the keys in .secrets need to look like:

GITHUB_TOKEN=b...
TEST_STRIPE_PUBLISHABLE_KEY=pk_test_...
TEST_STRIPE_SECRET_KEY=sk_test_...

@hibariya
Copy link
Collaborator

hibariya commented Mar 6, 2021

I noticed that the environment variables PREMIUM and BASIC defined in ci.yml have to belong to the same account as one the TEST_STRIPE_SECRET_KEY belongs. If variables from another account were used, Stripe API returns 400. For that reason, to run tests with a TEST_STRIPE_SECRET_KEY which is different from the one used in CI, we should avoid hard-coding the variables in ci.yml.

As a way to do that, perhaps we can read the variables from secrets.

hibariya added a commit to hibariya/checkout-single-subscription that referenced this issue Mar 10, 2021
By this jobs on ci.yml can be run on local machines with `act`.
Related to stripe-samples/sample-ci#6

Before applying this change, `TEST_PREMIUM_PRICE` and `TEST_BASIC_PRICE` have to be set as a secret.
hibariya added a commit to hibariya/accept-a-card-payment that referenced this issue Mar 11, 2021
By this jobs on ci.yml can be run on local machines with `act`.
Related to stripe-samples/sample-ci#6
hibariya added a commit to hibariya/subscription-use-cases that referenced this issue Mar 11, 2021
By this jobs on ci.yml can be run on local machines with `act`.
Related to stripe-samples/sample-ci#6
cjavilla-stripe pushed a commit to stripe-archive/accept-a-card-payment that referenced this issue Mar 11, 2021
By this jobs on ci.yml can be run on local machines with `act`.
Related to stripe-samples/sample-ci#6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants