Query SQL Server Create User And Grant Select to single database

 CREATE LOGIN [username] WITH PASSWORD = 'password', DEFAULT_DATABASE = [database_name]

GO


USE database_name;

CREATE USER username FOR LOGIN username;

GO 


GRANT SELECT TO username

GO


Setup Gitlab CI / CD git pull tanpa password

 1. ubah atau clone dari gitlab dengan ssh url

git remote set-url origin {url_ssh}

2. buat ssh key di server cpanel jika belum ada :

ssh-keygen -t ed25519 -C "youremailaddress@domain.tld DAY-MONTH-YEAR" -f ~/.ssh/my_key


3. bikin file config di ~/.ssh

diisi :

Host remote-git-repo-domain.tld
IdentityFile ~/.ssh/my_key

setup ssh to server

copas ssh self to server

 cat ~/.ssh/id_rsa.pub | ssh root@ip_address "cat >> ~/.ssh/authorized_keys"

Mengamankan CodeIgniter

 Contoh Controller :

<?php

class Jobvacancy extends CI_Controller
{
public function addjob()
{
$this->load->library('form_validation');
if ($this->input->method() === "post") {
$data["job"] = $this->input->post();

$rules = [
[
'field' => 'name',
'label' => 'Name',
'rules' => ''
],
[
'field' => 'job_image_url',
'label' => 'Image URL',
'rules' => 'valid_url'
],
[
'field' => 'job_url',
'label' => 'Job URL',
'rules' => 'valid_url'
],
];

$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == FALSE) {
return $this->load->view('add_job_form');
}

// di sini biasanya dilakukan penyimpanan ke database

return $this->load->view("list_job", $data);
}

$this->load->view('add_job_form');
}
}

Contoh View

<form id="form-add" action="" method="post">
<label for="name">Vacancy Job name</label>
<input type="text" name="name" value="<?= htmlentities(set_value('name'), ENT_QUOTES) ?>">
<div style="color: tomato;">
<?= form_error('name') ?>
</div>
<br>
<label for="job_image_url">Image URL</label>
<input onchange="previewImage(this)" type="url"
pattern="[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)"
name="job_image_url" value="<?= htmlentities(set_value('job_image_url'), ENT_QUOTES) ?>">
<div style="color: tomato;">
<?= form_error('job_image_url') ?>
</div>
<div id="image-preview"></div>
<br>
<label for="job_url">Job URL</label>
<input type="url"
pattern="[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)"
name="job_url" value="<?= htmlentities(set_value('job_url'), ENT_QUOTES) ?>">
<div style="color: tomato;">
<?= form_error('job_url') ?>
</div>
<br>
<input type="submit" value="Simpan">
</form>

<script type="text/javascript">
function previewImage(event) {
const previewContainer = document.querySelector('#image-preview');
const form = document.querySelector('#form-add');
if (form.checkValidity()) {
const imageURL = event.value;
previewContainer.innerHTML = `
<img src="${imageURL}" height="200" width="200" />
`;
}
}
</script>



DUMP & RESTORE POSTGRE

Backup :

 sudo pg_dump -U {user} -h {host} {db_name} > /{path}/{file}.sql

Restore :

psql -U {user} -h {host} {db_name} < /{path}/{file}.sql

Catatan Restore Docker n DB

 Catatan Docker Command :



login

docker login registry.gitlab.com


docker images


 docker pull registry.gitlab.com/aksiteknologi/etos:latest


docker run -p 80:80 -d --name <container_name> <url_images>


docker image prune --filter="dangling=true"


docker stop <container_name>

docker rm <container_name>


untuk melihat container di dalam docker 

#docker ps


untuk masuk dalam container

#docker exec -it <nama-container> bash

#apache


sudo docker stop <nama-container>

sudo docker rm <nama-container>




sudo sh -c 'nohup mysql -h127.0.0.1 --user=root --password=xxxx -f -D db_name < db_file.sql 1>stdout_output.txt 2>stderr_output.txt &'


Docker ERROR Debugging


$ /home/gitlab-runner/nganu

$ docker-compose logs nginx -f



cek log container

docker container logs -f <container-name>



=====



gitlab-runner verify


sudo apt remove docker-compose -y


sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose


sudo chmod +x /usr/local/bin/docker-compose


sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose


docker-compose --version



gitlab-runner restart


gitlab-runner status


cat /etc/gitlab-runner/config.toml