---
# System prepended metadata

title: CI/CD

---

# CI/CD

#### Gitlab
```yaml=
deploy:
  image: ubuntu:latest
  only:
    - master
  before_script:
    - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
  script:
    - ssh -o StrictHostKeyChecking=no $USERNAME@$HOST "cd ~/prieds/sarginsu-prieds-ui && git pull origin master && npm i && ng build --prod && rm -rf /var/www/html && mv dist/testing-app /var/www/html"
```

#### Github
```yaml=
name: CD
on:
  push:
    branches: [ master ]
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: deploy using ssh
        uses: appleboy/ssh-action@master
        with:
          host: ${{secrets.HOST}}
          username: ${{secrets.USERNAME}}
          key: ${{secrets.PRIVATE_KEY}} 
          port: 22
          script: |
           cd ~/prieds/sarginsu-prieds-ui/
           git commit -am 'server pull oke'
           git pull origin master
           npm i
           ng build --prod
           rm -rf /var/www/html
           mv dist/testing-app /var/www/html
```

#### Secret/Variabel yang perlu di tambah
> Diisi dengan info server yang akan di deploy. Agar runner bisa mengakses dan mendeploy aplikasi kita.
```
HOST
USERNAME
PRIVATE_KEY
```