Deploy your website from Github/Gitlab actions with Hostme

Here are steps to deploy your website to Hostme using Github/Gitlab actions




What are Github actions (or Gitlab CI) ?

GitHub Actions are event-driven, meaning that you can run a series of commands after a specified event has occurred. For example, every time someone creates a pull request for a repository, you can automatically run a command that executes a software testing script.



How to set up the deployment stage on Github/Gitlab actions and deploy to Hostme ?

1. Register to Hostme (and activate your account)

2. Get your API Tokens : On your admin page, you have a section "Advanced" with API Tokens menu, click there, then click on "+  Generate new token". You will have a modal with a token, copy this token to a secured place.

3. Then you can add this code to your .yml file

curl -v -X POST -H "Accept: application/json" -H "Authorization: Bearer <your API Token>" -F "file=@./<your zip file>.zip" https://hostme.space/api/websites/<your project slug name>/deploy_on_push


Full example : Angular Project deployed with Gitlab CI

On our Angular project, we add a gitlab-ci.yml.
This file contains the code below : 



# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml

# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#

cache:
  untracked: true
  key: "$CI_BUILD_REF_NAME"
  paths:
    - node_modules/

stages:      # List of stages for jobs, and their order of execution
  - install_build_and_deploy

install_dependencies:
  stage: install_build_and_deploy
  image: node:12-alpine
  tags:
    - docker
  script:
    - npm install @angular/cli
    - npm install
    - apk add zip unzip curl
    - echo "Compiling the code..."
    - ./node_modules/.bin/ng build --prod
    - echo "Compile complete."
    - cp ./.htaccess dist/ecommerce-angular-template/.htaccess
    - echo "Deploying application..."
    - cd dist/ecommerce-angular-template
    - zip -r genuka_template.zip .
    - mv genuka_template.zip ../../genuka_template.zip
    - cd ../../
    - ls -al
    - |
      curl -v -X POST -H "Accept: application/json" -H "Authorization: Bearer 1|r5FyY51ezlIWELsKbfwbPfM9i7vVLVFoiEVbRmef1" -F "file=@./genuka_template.zip" https://hostme.space/api/websites/genuka_angular/deploy_on_push

Share your response

0 Responses on this post

New project ?

Easily host your website with Hostme. Want to know more about how it works ?