How to get version id of AWS codebuild artifact that is uploaded to S3? - aws-codebuild

I have an AWS Codebuild that gets the code from GitHub and after a successful build, it uploads the artefact to an s3 bucket. The bucket has versioning enabled. I want to create a new git release tag after every successful build which will contain the s3 version id of the artefact uploaded. How is that achievable?
My buildspec.yaml looks as follows
version: 0.2
phases:
install:
commands:
- echo install phase started on `date`
- npm i
build:
commands:
- echo build started on `date`
- npm run build
post_build:
commands:
- echo post_build started on `date`
artifacts:
files:
- '**/*'

Related

How can I deploy a package to a private npm repository from Circleci?

I have read through many stack overflow questions and official documentation from Circleci but for some reason it will not let me publish packages via ci/cd.
No matter what I do I consistently get the following
error message
I have reset the NPM_TOKEN and know that it is correct and I don't see the issue with my code. according to the docs it should work but it does not. Am I missing something obvious?
Here is what I have tried
jobs:
publish:
executor: node
steps:
- checkout
- install
- run:
name: Build package
command: yarn build // tsc builds package to the lib directory
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
- run:
name: Publish library
command: npm publish lib
also
jobs:
publish:
executor: node
steps:
- checkout
- install
- run:
name: Build package
command: yarn build // tsc builds package to the lib directory
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/project/.npmrc
- run:
name: Publish library
command: npm publish lib
and
jobs:
publish:
executor: node
steps:
- checkout
- install
- run:
name: Build package
command: yarn build
- run:
name: Publish library
command: |
npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN
npm publish lib
and a few other variations but they were more tinkering, the above are examples that I have seen as documentation

Deploy Vue.js application to gitlab pages even though deployment is successful nothing is displayed

I am trying to deploy a sample Vue.js application to Gitlab pages but even though deployment has passed successfully nothing is rendered when I try to hit the served URL.
Here is my deployment code(.gitlab-ci.yml):
pages:
image: node:latest
stage: deploy
script:
- npm install --progress=false
- npm run build
- mkdir .public
- cp -r dist/* .public
- mv .public public
artifacts:
expire_in: 1 week
paths:
- public
only:
- master
I tried to locally serve the pages after npm run build from the /dist folder and its working all fine. I am not sure if there are any issues in my deployment script in Gitlab.
How do I get my application running in Gitlab pages?
I am using vuejs2and vue-cli-3 for bundling the scripts.
I figured out the issue with my code. The public folder contained duplicate data due to which it was not rendering the application properly.
Here is the working version of the deployment script:
pages:
image: node:latest
stage: deploy
script:
- npm install --progress=false
- npm run build
- rm -rf public
- mkdir public
- cp -r dist/* public
artifacts:
expire_in: 1 week
paths:
- public
only:
- master
After pipeline process is completed access the Gitlab pages of your repository. You should see the app rendering as expected.

Vue.js application does not run on Gitlab pages

I built a Vue.js Vuex user interface. It works perfectly (on my laptop). I want to deploy it on Gitlab pages.
I used the file described here (except that I upgraded the Node.js version):
build site:
image: node:10.8
stage: build
script:
- npm install --progress=false
- npm run build
artifacts:
expire_in: 1 week
paths:
- dist
unit test:
image: node:10.8
stage: test
script:
- npm install --progress=false
- npm run unit
deploy:
image: alpine
stage: deploy
script:
- apk add --no-cache rsync openssh
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa
- chmod 600 ~/.ssh/id_dsa
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- rsync -rav --delete dist/ user#server.com:/your/project/path/
The job is marked as run successfully on the pipeline. However when I click on the pages URL I get a 404 HTTP error code.
What am I missing?
I was facing a similar issue when I was trying to deploy my Vue.js application to Gitlab pages. After weeks of trial and error, I have got it to work.
Seeing your above script your building the app, unit testing it and trying to deploy it to an external server. If you need it in Gitlab pages as well you have to use the pages job.
Here is my pages job for deploying a vue.js app to Gitlab pages:
pages:
image: node:latest
stage: deploy
script:
- npm install --progress=false
- npm run build
- rm -rf public
- mkdir public
- cp -r dist/* public
artifacts:
expire_in: 1 week
paths:
- public
only:
- master
Hope this is what you're looking for.
You can deploy without the pipeline. In order for this to work you have to first build your application for production. If you have used Vue cli this is done by invoking the build command. ex. npm run build
This will generate a dist folder where your assets are. This is what you have to push in your repository. For example, look at my repository.
https://github.com/DanijelH/danijelh.github.io
And this is the page
https://danijelh.github.io/

Can't get drone.io CI to share files between pipelin steps

here is my .drone.yml:
pipeline:
test:
image: node:10
commands:
- npm install --production
- npm run build --production
publish:
image: plugins/docker
repo: myhub/image_name
when:
event: push
branch: master
the command npm run build creates a folder named build with static files inside. However, the publish step fails when building the docker image. Here is my Dockerfile:
FROM node:10-alpine
RUN mkdir -p /app
WORKDIR /app
COPY build build
The error being: COPY failed: stat /var/lib/docker/tmp/docker-builder090186817/build: no such file or directory time="2018-05-28T21:19:25Z" level=fatal msg="exit status 1"
So I don't quite understand how to build some files in one step, and copy them in the docker publish step...
Thanks for your help!
So anything in the workspace will get shared to the next step ;)
Are you able to build the docker image without drone with just docker build .?
ie. You might want to try to change COPY build build to be COPY ./build /app/build or the something like it.

Continuous Deployment not working

I need to continually build a create-react-app application and deploy it to Amazon S3 bucket.
I have written the following CircleCi config.yml:
version: 2
jobs:
build:
docker:
- image: circleci/node:7.10
steps:
- checkout
- run: npm install
- run: npm run build
deployment:
prod:
branch: circle-config-test
commands:
- aws s3 sync build/ s3://http://www.typing-coacher.net.s3-website.eu-central-1.amazonaws.com/ --delete
What I think should happens:
I have a docker container, I install the application, build it and the files are resting ready in build folder.
I am running the command listed in CircleCi docs and the build files are moving from the docker machine to s3 bucket.
To deploy a project to S3, you can use the following command in the
deployment section of circle.yml:
aws s3 sync <path-to-files> s3://<bucket-URL> --delete
What actually happens:
Application is being install and build files are being created, but nothing happen with deployment. it doesn't even appear on the builds console.
What Am i missing?
disclaimer: CircleCI Developer Advocate
Everything from the deployment: line and down shouldn't be there. That's syntax for CircleCI 1.0 while the rest of your config file is CircleCI 2.0.
You can either:
Create a new step and check for the branch name with Bash. If it's circle-config-test, then run the deployment commands. You'll also need to install the AWS CLI in that build.
Using [CircleCI Workflows], create a deployment job with a branch filter for circle-config-test. You can use any image that contains the AWS CLI or install it yourself. The CI Builds: AWS Docker image contains this for you.