Skip to content

Commit

Permalink
adjust to use github token to download npm packages
Browse files Browse the repository at this point in the history
  • Loading branch information
hgw77 committed Nov 25, 2024
1 parent d53f3c6 commit b64b836
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .npmrc.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//npm.pkg.github.com/:_authToken=GITHUB_TOKEN
//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN
@sapcc:registry=https://npm.pkg.github.com
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ In Greek mythology Elektra, the bright or brilliant one, is the Goddess of Cloud

# Installing and Running Elektra

## Creating a GITHUB_TOKEN for Packages like `@sapcc/limes-ui`

To use packages like `@sapcc/limes-ui`, a **GITHUB_TOKEN** is required. The following steps are necessary:

1. **Create a Personal Access Token (PAT)**
1.1. Navigate to **Settings** > **Developer Settings** in your profile.
1.2. Under **Personal access tokens**, select **Tokens (classic)** and generate a new token.
1.3. Assign the permission **read:packages** to allow access to private packages.

2. **Configure the `.npmrc` File**
2.1. Copy the `.npmrc.sample` file to `.npmrc`.
2.2. Replace `$GITHUB_TOKEN` with the generated token in the `.npmrc` file.
Alternatively, you can export the token in the terminal: `export GITHUB_TOKEN=your_token_here`
3. Store the Token in the Concourse Pipeline
3.1. Navigate to vault/concourse-secrets/global/elektra/.
3.2. Replace the token content with the generated token.

## Steps to setup a local development environemnt

### MacOS
Expand Down Expand Up @@ -174,7 +191,7 @@ In Greek mythology Elektra, the bright or brilliant one, is the Goddess of Cloud
- Set the MONSOON*OPENSTACK_AUTH_API*\* values to your devstack/openstack configuration settings
- Enter the database configuration parameters

12. Copy the **.npmrc.sample** file to **.npmrc** and replace GITHUB_TOKEN with you private access token (PAT)
12. Copy the **.npmrc.sample** file to **.npmrc** and replace `$GITHUB_TOKEN` with you private access token (PAT)

13. Start the Elektra dashboard application
a. Run rails puma server
Expand Down
12 changes: 12 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ RUN apk upgrade --no-cache --no-progress \

################################### BUILDER ################################
FROM base AS builder

RUN echo "Rebuild image 1"
# Note: we need to install git here because bundle needs git in the next step
RUN apk --no-cache add git curl nodejs yarn shared-mime-info
Expand Down Expand Up @@ -81,8 +82,19 @@ RUN bundle config set --local without 'development integration_tests'
RUN bundle install --jobs=$(nproc)

# add elektra sources into image
ARG NPM_GITHUB_TOKEN
# Set the GITHUB_TOKEN environment variable
ENV GITHUB_TOKEN=$NPM_GITHUB_TOKEN
ADD . $APP_PATH

# Copy .npmrc.sample file into the container
ADD .npmrc.sample .npmrc
# Replace the $GITHUB_TOKEN placeholder with the actual token value
# this is needed to install npm packages from github
# the sed is needed because Docker doesn’t expand environment variables in .npmrc files directly,
# so writing $GITHUB_TOKEN in the .npmrc file won’t automatically replace it with the environment variable at build time.
RUN sed -i "s|\$GITHUB_TOKEN|$GITHUB_TOKEN|g" .npmrc

# transpile javascripts
#RUN yarn install --no-progress && yarn build --production && rm -rf node_modules
RUN bin/rails assets:precompile && rm -rf node_modules
Expand Down

0 comments on commit b64b836

Please sign in to comment.