Skip to content

ptrsp/Bangkit2021_B21-CAP0418_Pafin_CC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Deploy Restful Api to Cloud Run and Connecting with Cloud SQL

Restful Api with Codeigniter 3 Framework

Setup Cloud SQL

Create Cloud Instance Sql as pafin database

gcloud sql instances create instance_name --root-password your_password

Connect to Cloud Sql via Cloudshell

gcloud sql connect instance_name --user=root -p

Create Database for pafin

CREATE DATABASE pafin_db;

Create Table and insert sample record

--
-- Table structure for table `mahasiswa`
--
CREATE TABLE `users` (
  `userid` int(11) NOT NULL,
  `username` varchar(30) NOT NULL,
  `password` varchar(30) NOT NULL,
  `name` varchar(50) DEFAULT NULL,
  `email` varchar(50) NOT NULL,
  `telephone` varchar(20) DEFAULT NULL,
  `userstat` int(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `mahasiswa`
--
INSERT INTO `users` (`userid`, `username`, `password`, `name`, `email`, `telephone`, `userstat`) VALUES
(1000, 'peiterspasaribu', 'superuser', 'Peiter Solarso Pasaribu', '[email protected]', '082115105617', 1),
(1001, 'alexandroalve', 'superalex', 'Alexandro Alveorus', '[email protected]', '082115105615', 1),
(1002, 'rockysantoz', 'supersantoz', 'Rocky Dos Santoz', '[email protected]', '082115105616', 1);
--
-- Indexes for table `mahasiswa`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`userid`);
--
-- AUTO_INCREMENT for table `mahasiswa`
--
ALTER TABLE `users`
  MODIFY `userid` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1003;

Deploy Restful Api to Cloud Run

First Upload Application Restful Api to cloudshel

After that, create a Docker file inside restfull api folder

# Use the official PHP image.
# https://hub.docker.com/_/php
FROM php:7.4-apache

# Configure PHP for Cloud Run.
# Precompile PHP code with opcache.
RUN docker-php-ext-install -j "$(nproc)" opcache
RUN set -ex; \
  { \
    echo "; Cloud Run enforces memory & timeouts"; \
    echo "memory_limit = -1"; \
    echo "max_execution_time = 0"; \
    echo "; File upload at Cloud Run network limit"; \
    echo "upload_max_filesize = 32M"; \
    echo "post_max_size = 32M"; \
    echo "; Configure Opcache for Containers"; \
    echo "opcache.enable = On"; \
    echo "opcache.validate_timestamps = Off"; \
    echo "; Configure Opcache Memory (Application-specific)"; \
    echo "opcache.memory_consumption = 32"; \
  } > "$PHP_INI_DIR/conf.d/cloud-run.ini"

# Copy in custom code from the host machine.
WORKDIR /var/www/html
COPY . ./

# Use the PORT environment variable in Apache configuration files.
# https://cloud.google.com/run/docs/reference/container-contract#port
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf

# Configure PHP for development.
# Switch to the production php.ini for production operations.
# RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
# https://github.com/docker-library/docs/blob/master/php/README.md#configuration
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

Build dockerfile and push to gcr

gcloud builds submit --tag gcr.io/Your_ProjectID/restapi

Deploy to cloud run

gcloud run deploy --image gcr.io/Your_ProjectID/restapi --platform managed --add-cloudsql-instances YOUR_CLOUDSQL_INSTANCE_CONNECTION_NAME --set-env-vars CLOUD_SQL_CONNECTION_NAME=YOUR_CLOUDSQL_INSTANCE_CONNECTION_NAME

result of conclusiont : failed to connect restful api residing in cloud run with cloud sql instance.

Upload ML Model to cloud

Open powershell in GCP,ensure that cloud shell connect into your account and project Clone this repository git clone https://github.com/ptrsp/Bangkit2021_B21-CAP0418_Pafin_CC.git

gsutil cp tokenizer.pickle gs://[project-id]-bucket
gsutil cp variables.data-00000-of-00001 gs://[project-id]-bucket
gsutil cp variables.index gs://[project-id]-bucket

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages