i want to use Github Actions for deploying my react nodejs code to nginx. For this i've run those commands:
curl -o actions-runner-linux-x64-2.301.1.tar.gz -L
https://github.com/actions/runner/releases/download/v2.301.1/actions-runner-linux-x64-2.301.1.tar.gz
tar xzf ./actions-runner-linux-x64-2.301.1.tar.gz
yes "" | ./config.sh --url https://github.com/yuuval/react-deploy-aws --token AVYXWHVAXX2TB4J63XBJCIDDYB6TA
sudo ./svc.sh install
sudo ./svc.sh start
Those are the essential commands. I want, that i can use this token also for other ec2 instances: AVYXWHVAXX2TB4J63XBJCIDDYB6TA. I've set a repository secret with a value, but it doesn't work. I want to run this commands by terraform and cloud-init, thats why i can't just copy the token from the online github page. So does anyone know how i can set a fix token, so i can create multiple instances with terraform and cloud-init. Isn't it enough if the token is given in the workflow file?
workflow file:
**# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
jobs:
build:
runs-on: self-hosted
strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
token: ${{ secrets.ACTIONS_TOKEN }}
- run: npm ci
- run: npm run build --if-present
After this command yes "" | ./config.sh --url https://github.com/yuuval/react-deploy-aws --token AVYXWHVAXX2TB4J63XBJCIDDYB6TA this happens:
Http response code: NotFound from 'POST https://api.github.com/actions/runner-registration' (Request Id: 9530:5EB4:1A2D16B:35B9403:63D2A781)
{"message":"Not Found","documentation_url":"https://docs.github.com/rest"}
Response status code does not indicate success: 404 (Not Found).
Related
I am trying to run a service written in Scala in a docker container and when running the service I have the following exception:
Caused by: java.lang.UnsatisfiedLinkError: C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\jni-mt5-17287867478131106707\\mt5_lib.dll: Can't find dependent libraries
This app has a dependency on a library that loads the mt5-lib.dll mentioned above.
The exception suggests that I am missing some libraries. What is strange about this problem is that I already encountered this problem while writing the Dockerfile, and solved it by installing the vc_redist (https://aka.ms/vs/17/release/vc_redist.x64.exe).
Still if I locally build the image and run it, I don't have the mentioned problem. I only have the problem if I build the image using GitHub actions and push it to Amazon ECR, and then pull it from ECR and run it, which is the way that I want to do it.
The project is written in Scala, version 2.12.7, using sbt version 1.2.7. The Dockerfile is below:
FROM eclipse-temurin:11.0.16.1_1-jdk as deps
ENV SCALA_VERSION 2.12.7
ENV SBT_VERSION 1.2.7
ENV AWS_ACCESS_KEY_ID=
ENV AWS_SECRET_ACCESS_KEY=
ENV AWS_DEFAULT_REGION=
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ADD https://github.com/sbt/sbt/releases/download/v1.2.7/sbt-1.2.7.msi sbt-1.2.7.msi
RUN Start-Process 'sbt-1.2.7.msi' '/qn' -PassThru | Wait-Process;
COPY . .
RUN sbt 'project app' universal:packageBin
RUN Expand-Archive -LiteralPath "C:\app\target\universal\app-1.0.0-SNAPSHOT.zip" -DestinationPath "c:\\"
FROM eclipse-temurin:11.0.16.1_1-jdk
COPY --from=deps /app-1.0.0-SNAPSHOT/ c:/app/
RUN Invoke-WebRequest -Uri "https://aka.ms/vs/17/release/vc_redist.x64.exe" -OutFile "c:\vc_redist.x64.exe"
RUN c:\vc_redist.x64.exe /install /norestart
RUN New-Item "c:\app\logs" -Type Directory
WORKDIR "c:\app"
ENTRYPOINT ".\start-svc.bat"
The build.yaml file for GitHub actions is below:
name: App build
on:
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- 'master'
jobs:
build:
runs-on: windows-2019
steps:
- uses: actions/checkout#v2
# Configure AWS
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials#v1
with:
aws-access-key-id: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION_EU_WEST_1 }}
# Login to ECR
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login#v1
# Build the Docker image
- name: Build
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: my/ecr/repo
IMAGE_TAG: ${{ github.ref_name }}
run: |-
docker build -t "$Env:ECR_REGISTRY/$Env:ECR_REPOSITORY`:app-$Env:GITHUB_SHA" -f app\Dockerfile .
docker push "$Env:ECR_REGISTRY/$Env:ECR_REPOSITORY`:app-$Env:GITHUB_SHA"
When I figured out that when I locally build the docker image, it runs with no problems, I really only tried to change the windows image on the GitHub actions from windows-2019 to windows-latest, but that didn't help.
I really don't have any more ideas, so any suggestion is welcome.
I am working with a mono repo and I would like to deploy my back-end (only) with the Cloud Run service (using the "official" google cloud run action). For this action, I need a Dockerfile at the root of my project for building my image. But my Dockerfile is under ./server.
Is there a way to use something like working-directory for the run steps ? I didn't find anything from the doc.
Or do I have to have a Dockerfile at the root of my project and the Dockerfile points to the ./server?
My project tree :
./
.github/
worflows/
deploy-back.yml
client/
...
server/
...
Dockerfile
# deploy-back.yml
name: Deploy to production
# ...
jobs:
deployment-job:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout#v2
- name: Authenticate to Google Cloud
uses: google-github-actions/auth#v0
with:
# ...
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun#v0
with:
service: ${{ env.SERVICE_NAME }}
source: gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ env.PACKAGE_VERSION }}
project_id: ${{ env.PROJECT_ID }}
region: ${{ env.RUN_REGION }}
tag: ${{ env.PACKAGE_VERSION }}
Since you are working on a monorepo and wants to run this particular workflow to deploy only when backend code base gets changed, I would start by limiting the trigger by only changes related to the /server folder.
on:
push:
paths:
- 'server/**'
As for the Dockerfile location, I would keep under /server just because it's a monorepo. Now, to answer your question the Cloud Run GitHub actions you provided is expecting a parameter which points to your Docker image
source: gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ env.PACKAGE_VERSION }}
which means your Docker image has to be already built prior to run the "Deploy to Cloud Run" step. What I would do, add two Docker steps prior to the deployment so github actions can build the image:
- name: Docker auth
run: gcloud auth configure-docker
- name: Docker build backend
run: docker build -t gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ env.PACKAGE_VERSION }} . -f server/Dockerfile
- name: Docker push backend
run: docker push gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE_NAME }}:${{ env.PACKAGE_VERSION }}
Note the -f server/Dockerfile in the Docker build step which will point to the server folder and run the build from there or if you want (using bash) you can just change the directory during the build: cd server/ then run the docker build ...
I've created a monorepo based on yarn workspaces and lerna which contains the following package types:
UI website package (Vue Vite application)
DTO package (private npm package)
n backend packages (AWS serverless)
And my project structure looks something like this
root
-- package.json
-- packages/
--- ui/
---- package.json
---- dist/
--- dto/
---- package.json
---- dist/
--- serverlessBackend1/
---- package.json
---- build/
--- serverlessBackend2/
---- package.json
---- build/
--- serverlessBackendN/
---- package.json
---- build/
The DTO package contains mostly types, which are used within every other package, therefore it's listed as dependency in every package.json of my packages.
In my root package.json I have the following three basic lerna scripts:
{
[...]
"workspaces": [
"packages/*"
],
"scripts": {
"build": "lerna run build",
"publish": "lerna publish --conventional-commits --yes",
"deploy": "lerna run deploy"
},
"dependencies": {
[...]
},
"devDependencies": {
[...]
}
}
Now I wanted to create a github actions pipeline, which takes care of distributing the different packages to their destinations. Ftp upload for the website bundle, publishing the dto package to npm and deploying all serverless projects to AWS.
As I'm pretty new to Github actions, I've dug my way through offical documentation, readmes, other projects, stackoverflow questions and managed to set up a pipeline, which works in two of three cases.
Unfortunately the step, where I want to deploy all serverless packages to AWS seems to have a weird issue. First, this is how the Job is configured:
Deploy-to-AWS:
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout#v2
with:
submodules: recursive
token: ${{ secrets.GITHUB_TOKEN }}
- name: Installing dependencies
run: yarn
- name: Add AWS credentials with profile
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY }} --profile ${{ secrets.PROFILE_NAME }}
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} --profile ${{ secrets.PROFILE_NAME }}
- name: Deploy to AWS dev
run: yarn deploy
When I execute yarn deploy locally from within my root dir, everything works as expected and the deploy script in each serverless package is executed and all packages are deployed correctly. This is how the package.json does look like in the serverless packages:
{
[...]
"scripts": {
"build": "tsc",
"runDeployment": "serverless deploy -v --aws-profile my-profile-name",
"deploy": "npm run build && npm run runDeployment"
},
"dependencies": {
"#userName/my-private-dto-package": "^0.3.2",
[...]
},
"devDependencies": {
[...]
}
}
But when I try the same within the Github actions workflow, I receive an error that the my private package module cannot be found:
2nd-serverless-package: path/to/file/where/dto/is/imported.ts(1,88): error TS2307: Cannot find module '#userName/my-private-dto-package' or its corresponding type declarations.
This seem to happen to every package but the first. So perhaps the dependency is just resolved for the first package?
I've searched the internet up and down but to no avail.
I think it might has something to do with the dependencies being symlinked and therefore the DTO package is just available on root level and not directly inside the serverless package.
But I solved it by separating the workflows for each serverless package and installing the dependencies directly.
name: Serverless deployment package-name
on:
push:
branches:
- main
paths:
- 'packages/serverlessBackend1/**'
jobs:
Deploy-to-AWS:
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPMRC_AUTH_TOKEN }}
steps:
- name: Check out repository code
uses: actions/checkout#v2
- name: Setup up node
uses: actions/setup-node#v2
- name: Provide profile credentials
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY }} --profile my-profile-name
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} --profile my-profile-name
- name: Install dependencies
run: cd packages/serverlessBackend1 && npm install
- name: Deploy event backend to AWS dev
run: cd packages/serverlessBackend1 && npm run deploy
This solved it for me entirely. Not the solution to my initial question, therefore not marking it as answer but I thought my findings could perhaps help somebody else.
I want to build and deploy my expo app in vercel. I know that I can build it locally (expo build:web), cd into the build folder and run vercel, but I would like it to be done automatically with source control integration.
So I have connected my github repository, npm install seems to be working ok. The problem is with the build command. I tried expo build:web but this failed because the expo cli is not installed in vercel, so I tried npx expo-cli build:web and got the folloowing output: Command "npx expo-cli build:web" exited with 1.
Error: Could not find MIME for Buffer <null>
at /vercel/.npm/_npx/727/lib/node_modules/expo-cli/node_modules/xdl/src/Webpack.ts:294:23
at finalCallback (/vercel/.npm/_npx/727/lib/node_modules/expo-cli/node_modules/webpack/lib/Compiler.js:257:39)
Does anyone know how I can run expo build:web in vercel? Many thanks
From my perspective, I think you need to use something like GitHub actions for this task.
I wrote a post on How I automated the releases with the expo-cli and I think we need to follow the same logic.
// .github/workflows/staging.yml
name: Expo Publish on Staging
on:
push:
branches:
- develop
jobs:
publish:
name: Install and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- uses: actions/setup-node#v1
with:
node-version: 12.x
- uses: expo/expo-github-action#v5
with:
expo-version: 3.x
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
expo-cache: true
- run: yarn
- run: expo build:web <------- not sure if it works tho
- run: <------- here we need a way to upload to vercel
I am in the same situation as you —trying to automate the react-native-web to vercel release.
I had the same issue, but found a solution. expo build:web creates a production ready static bundle in the web-build/ directory, which Vercel can deploy. Thus, to deploy the Expo Web-app to Vercel, one can first have a GHA-step that runs expo build:web and then deploy the bundle it produces to Vercel.
Note that one either has to specify the path to the web-build directory as the root-directory in Vercel (which is done in the code below) or has to set the working-directory to the web-build-path in the Vercel step in the code.
Full Github Actions code for job:
deploy-web-staging:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup .npmrc and use node 14.15.1
uses: actions/setup-node#v1
with:
node-version: 14.15.1
- name: Expo Web
uses: expo/expo-github-action#v5
with:
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
expo-cache: true
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn
- name: Build Expo Web
working-directory: ./packages/app
run: expo build:web
- name: Vercel Deploy
uses: amondnet/vercel-action#v20.0.0
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-org-id: VERCEL_ORG_ID
vercel-project-id: VERCEL_PROJECT_ID
scope: TEAM
I'm trying to deploy micro services that are part of a mono repo, for this I'm using github actions but I'm having an issue related to the plugins in the package.json files. This is the structure of my project:
--repo
---package.json
---resources
----package.json
---services
----Service A
-----package.json
----Service B
-----package.json
First I'm trying to deploy the resources folder that basically creates S3 buckets, cognito user pool, etc... and I have added the plugin called "serverless-cognito-add-custom-attributes" as part of this project, this plugin only exists on the package.json that is inside the "resources" folder.
I'm getting this error when trying to deploy from github actions :
Serverless plugin "serverless-cognito-add-custom-attributes" not found. Make sure it's installed and listed in the "plugins" section of your serverless config file.
this is the .yml file I'm using on github actions:
name: Deploy Resources to Dev
on:
push:
branches:
- dev
tags:
- RC-*
paths:
- './resources'
jobs:
InstallActions:
name: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Download Node
uses: actions/setup-node#v1
with:
node-version: "12.x"
- name: Install NPM Global Packages
run: |
npm install --global
npm install "./resources" --global
- name: Serverless Deploy
uses: serverless/github-action#master
with:
args: deploy --stage dev --config "./resources/serverless.yml"
env:
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_DEV}}
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY_DEV}}
When the above .yml file run I can see this on the console:
+ ----#1.0.0
added 1 package in 2.935s
+ resources#1.0.0
added 3 packages from 3 contributors in 0.654s
for some reason it seems that
uses: serverless/github-action#master
is unable to find the packages when installed from a sub folder, but doing all manually seems to work fine:
name: Deploy Resources to Dev
on:
push:
branches:
- dev
tags:
- RC-*
paths:
- './resources'
jobs:
Deploy:
name: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Download Node
uses: actions/setup-node#v1
with:
node-version: "12.x"
- name: Install Serverless Framework
run: npm install -g serverless
- name: Serverless Authentication
run: sls config credentials --provider aws --key ${{secrets.AWS_ACCESS_KEY_DEV}} --secret ${{secrets.AWS_SECRET_ACCESS_KEY_DEV}}
- name: Install NPM dependencies
run: |
npm install
npm install "./resources"
- name: Deploy to AWS
run: serverless deploy -v -s dev
working-directory: "./resources"
I had this problem for around 17 hours and then decided to go all manual instead of using the package serverless/github-action#master