How to host go api on GCP
I am new to this deployment and on my local computer my project api written in GOLANG which is already dockerized and uses mariadb as backend. It will execute on port 8080 when I run the command "docker-compose up". What are the different ways to deploy on GCP and which one is the easy one?
1 answer
-
answered 2022-05-06 19:03
rickyticotaco
Since your Golang project is already containerized, I would probably take a look at Cloud Run.
Deploy a container to Cloud Run
Cloud Run gives you two options:
- You can deploy your container after you push it to an Artifact Registry repository
- You can deploy your application straight to Cloud Run from the code source following this guide: Deploying to Cloud Run from source
Another option would be Google AppEngine. You are more limited in terms of what runtime you can choose, but you could deploy your application without even worrying about creating a container first.
Create a Go 1.12+ app in the App Engine standard environment
If you need to deploy your MariaDB instance in GCP too, I'd look into running it in a Compute Engine instance if it's just a prototype or development environment. Otherwise, you can look into Google Cloud Marketplace options (e.g. https://console.cloud.google.com/marketplace/product/mariadb-public/mariadb-for-gcp).
do you know?
how many words do you know
See also questions close to this topic
-
Google Cloud Compute Engine http Connection Timeout
I have setup a compute engine VM with 2vCPU and 2GB RAM.I have setup nginx server and setup the firewalls permissions as shown in the diagram. When I try to access the angular files hosted on the server using the external IP I get the error "The connection has timed out" and when I try to use curl on the terminal, it displays the error "curl: (28) Failed to connect to IP port 80 after 129163 ms: Connection timed out".
Both the Http and Https firewall rules are enabled
Whe I run the command
sudo systemctl status apache2
netstat -tulpn | grep LISTEN
enter code here
Any ideas on what the issue might be will be really helpful
-
(Terraform) Error 400: Invalid request: instance name (pg_instance)., invalid
On GCP, I'm trying to create a Cloud SQL instance with this Terraform code below:
resource "google_sql_database_instance" "postgres" { name = "pg_instance" database_version = "POSTGRES_13" region = "asia-northeast1" deletion_protection = false settings { tier = "db-f1-micro" disk_size = 10 } } resource "google_sql_user" "users" { name = "postgres" instance = google_sql_database_instance.postgres.name password = "admin" }
But I got this error:
Error: Error, failed to create instance pg_instance: googleapi: Error 400: Invalid request: instance name (pg_instance)., invalid
Are there any mistakes for my Terraform code?
-
Apache beam FixedWindow doesn't do anything after GroupByKey transform
I built a pipeline which reads from confluent kafka it processes the records and then use side outputs to split them into rejected and approved pcollections, then the approved pcollections gets written to bigquery, but I want to persist the approved records and write them into a file on gcs.
The code is:
windowing=(aproved | 'Create_window' >> beam.WindowInto(window.FixedWindows(60)) | 'AddKey' >> beam.Map(lambda record: (none,record)) | 'GBK' >> beam.GroupByKey() | 'remove_key' >> beam.FlatMap(ret_key) | 'AddTimeStamp' >> beam.Map(lambda record: beam.window.TimestampValue(record,time.time())) | 'Write' >> WriteToFiles(path=MY_BUCKET,file_naming=destination_prefix_naming('.ppl')) )
This works when I test it reading from a file and using direct runner, but when I use dataflow and streaming it just doesn't do anything after the GroupByKey transform, it says on the graph that 20 element were added, but the next transform ('remove_key') never gets an element after that
-
how do i store maven dependencies inside docker image using a Dockerfile
so im making a spring boot application that im supposed to put in and run from a docker container, and i would like to build the whole image using a docker file.
im using this dockerFile:FROM openjdk:8-jdk-alpine ADD . /analytics-service WORKDIR /analytics-service ENTRYPOINT ./mvnw spring-boot:run
when i create the image it just copies the files, and only after i run it, it starts downloading all the maven dependencies. which takes a while, given that i will be running a few containers. so how do i do it ? i want it to get all the dependencies when the image is created, so when i create a container it doesnt start downloading.
-
Uncaught Error: Class 'Service\UsersService' not found
I'm trying to run my php-based application, which connects to a mysql DB, launched through docker-compose.
i get this message when i connect to localhost:
Fatal error: Uncaught Error: Class 'Service\UsersService' not found in /var/www/html/dic/users.php:3 Stack trace: #0 /var/www/html/web/index.php(3): require() #1 {main} thrown in /var/www/html/dic/users.php on line 3
user.php
<?php return new Service\UsersService( require "../config/db-connection.php" );
UsersService.php
<?php namespace Service; use Entity\User; use PDO; class UsersService { protected $db; public function __construct(PDO $db) { $this->db = $db; } public function getLastJoined(): array { return $this->db->query( "SELECT id, joined, name FROM user ORDER BY joined DESC LIMIT 10" )->fetchAll(PDO::FETCH_CLASS, User::class); } public function getById(string $id): ?User { $user = $this->db->query("SELECT id, joined, name FROM user WHERE id = " . $this->db->quote($id))->fetchObject(User::class); return ($user === false) ? null: $user; } }
index.php
<?php $lastJoinedUsers = (require "../dic/users.php")->getLastJoined(); switch (require "../dic/negotiated_format.php") { case "text/html": (new Views\Layout( "Twitter - Newcomers", new Views\Users\Listing($lastJoinedUsers), true ))(); exit; case "application/json": header("Content-Type: application/json"); echo json_encode($lastJoinedUsers); exit; } http_response_code(406);
I appreciate any help!!
-
Docker compose specified port not mapping to connect to the health check endpoint
I am a newbie to docker. This is the layout I am working with. I have 2 projects in the docker compose file. A dotnet6 web api and a mvc web app. In the web api startup.cs I have the following code to get health statuses using AspNetCore.HealthChecks.UI, If I browse to the endpoint I get a json object of health check values (this part works)
app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapHealthChecks("/hc", new HealthCheckOptions { Predicate = _ => true, ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); });
I have a WebStatus .Net core MVC app whose job is to display health stats using the healthcheck UI. The appsetting for this is:
{ "HealthChecks-UI": { "HealthChecks": [ { "Name": "TestApp API Health Check", "Uri": "https://localhost:7100/hc" }, { "Name": "TestApp API Health Check (Local)", "Uri": "https://localhost:7141/hc" } ], "Webhooks": [ { "Name": "", "Uri": "", "Payload": "", "RestoredPayload": "" } ], "EvaluationTimeOnSeconds": 10, "MinimumSecondsBetweenFailureNotifications": 60 }, "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*" }
And the docker compose file is as shown below
version: '3.4' services: testapp.api: environment: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=https://+:443;http://+:80 ports: - "8005:80" - "7100:443" volumes: - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro webstatus: environment: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=https://+:443;http://+:80 - HealthChecksUI__HealthChecks__0__Name=Test App API Health Check - HealthChecksUI__HealthChecks__0__Uri=https://testapp.api/hc ports: - "8006:80" - "7101:443" depends_on: - testapp.api volumes: - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
If I start both the projects without docker, everything works, the WebStatus app shows the health status of the api as expected! However it doesn't work when I use docker compose to run this. The url I use to get to the webstatus app is https://localhost:7101/healthchecks-ui#/healthchecks
-
Hosting a Strapi 4 + Gatsby 4 website in the same NodeJs server
I am working on a business site with Events and Blog page that can be updated. For this I have chosen Gatsby 4 and Strapi 4. But in most of the tutorials, they have hosted these two separately like Heroku and Netlify/Digital Ocean. I am hoping for a cost effective NodeJs server from a local hosting service. How can I use the same NodeJS server to deploy a Gatsby 4 + Strapi 4 website?
-
reactjs project working fine on local...but not working after deployment...any suggestion?
I'm trying to deploy my first reactjs app. (It's a quiz app) In local the app is working fine.. after deploy is not working as expected. Here you can find the deploy version and a soon you start to play answering the first question you will notice the problem that the question is not changing. Here is the github repository. I did google a lot , I try to deploy it in both github and netlify but I can't manage to resolve this problem. Any help is appreciate. Thanks
-
C# MariaDB Update Function working in DataStore but not updating in .NET Application
My initial issue is that my database does not update when I call on this specific code. I am not sure if it is C# itself or the update query that I am calling.
string _connectionString = "validConnectionstring"; using (MySqlConnection _mySqlConnection = new MySqlConnection(_connectionString) { _mySqlConnection.Open(); using (MySqlCommand command = new MySqlCommand("UpdateProfileStatus", _mySqlConnection)) { command.Transaction = _mySqlConnection.BeginTransaction(); command.CommandTimeout = TimeSpan.FromSeconds(60).Seconds; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@_username", "test"); command.Parameters.AddWithValue("@_status", true); command.ExecuteNonQuery(); } _mySqlConnection.Close(); }
I get no updates in my database but my console logs that the query is executed returning the value of 1 but there is no update that actually happens in my DB. Is there something in my code to reason why it is failing?
Here is the stored procedure that I have for the update command
CREATE PROCEDURE UpdateProfileStatus(_username VARCHAR(25), _status BOOL) UPDATE Profile SET status = _status WHERE username = _username;
I know the Stored Procedure works but am not sure why my .NET application is not responding to my procedure call. Is it something to do with my implementation of the parameters or is it my procedure itself?
-
Fastest Way To Execute a Query From 15,000,000+ rows
My database is around 15-20 billion lines long. I am planning to make a breach checking service (similar to leakcheck). After putting a small part of the database on a MariaDB test database I had installed, I noticed it takes around 4 seconds to run a query from a small portion (18m) of my total amount (15-20b) of rows. The table is formatted as follows: breach_id email password username ip phone number
Everything is in 1 table. If anyone can help me get the query time to under 1s I would be so appreciative.
VPS CPU: AMD EPYC 7313 16-Core Processor Ram: 62G Mem, 1.5G Swap Storage: 5TB
I have no issue in changing the database I use. The service will be non-profit and aims to help people
response of
show create table data_info;
+-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | data_info | CREATE TABLE `data_info` ( `database_id` int(11) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `password` varchar(255) DEFAULT NULL, `username` varchar(255) DEFAULT NULL, `ip` varchar(255) DEFAULT NULL, `phone_number` varchar(255) DEFAULT NULL, FULLTEXT KEY `email` (`email`,`password`,`username`,`ip`,`phone_number`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 | +-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.000 sec)
MariaDB [hackcheck]> explain select * from data_info where email = "fbi" -> ; +------+-------------+-----------+------+---------------+------+---------+------+----------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+-----------+------+---------------+------+---------+------+----------+-------------+ | 1 | SIMPLE | data_info | ALL | email | NULL | NULL | NULL | 18233866 | Using where | +------+-------------+-----------+------+---------------+------+---------+------+----------+-------------+
-
Sequence number, incorrect number
In a spring boot application, I have this entity
@Data @NoArgsConstructor @AllArgsConstructor @Entity public class User {
@Id @GeneratedValue(generator="user_id_seq") @SequenceGenerator(name="user_id_seq",sequenceName="user_id_seq", allocationSize=1) Long id ...
}
In mariadb, when I check the sequence
CREATE OR REPLACE SEQUENCE `user_id_seq` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB
In db, I have only 5 user.
select id from `user` u
This query return
1002 1004 1005 2007 3001
Why it's not 1, 2, 3, 4, 5
Is it beaucause of the cache 1000?
-
Step #0: exec: "gcc": executable file not found in $PATH
I keep running into this error when trying to deploy a very simple website to App Engine (this code without the Dockerfile, as specified in this tutorial).
I am running on macOS Monterey 12.2.1, go 1.18, fresh install of the Google Cloud SDK. I'm not using any external packages either.
Every time that I try to deploy, I get the
Step #0: exec: "gcc": executable file not found in $PATH
error. Here's a larger snippet:Step #0: go: finding golang.org/x/tools v0.0.0-20200904185747-39188db58858 Step #0: go: finding google.golang.org/grpc v1.31.1 Step #0: go: finding golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f Step #0: # net Step #0: exec: "gcc": executable file not found in $PATH Finished Step #0 ERROR ERROR: build step 0 "gcr.io/gcp-runtimes/go1-builder@sha256:408a098788ef4cdeec452821946b986ef82ce5ebceecbdf748ffecf329765bce" failed: step exited with non-zero status: 2
Any clues what is going wrong? I read some similar posts that it could be an error with the PATH, but I could not get anything to work for myself. Here is my path:
/usr/bin:/usr/local/go/bin:/Users/temporaryadmin/go/bin:/Users/temporaryadmin/google-cloud-sdk/bin:/Users/temporaryadmin/.pyenv/shims:/Users/temporaryadmin/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/usr/bin/python3:/usr/local/go/bin
Really struggling to understand what I can do to fix this so I can start uploading to App Engine. Thanks a lot!
-
Golang: convert custom type (alias to [32]byte) to string
This is related to GOLANG language. I can't find out how to convert a value that is of a custom type:
type Hash [32]byte
into a string representation of that hash:
myHash := CreateHash("This is an example text to be hashed") fmt.Printf("This is the hash: %s", string(myHash))
The error I'm getting is the following:
cannot convert myHash (variable of type Hash) to string compiler(InvalidConversion)
While I'm ok using just [32]bytes, I'd really like to know how to do this in GO; I have been for a while searching and couldn't find a solution this exact case.
Thanks in advance!
-
Golang - Create Array of Struct?
How to create an array of struct with user input ?
I am trying to create a loop that will get input from user for a struct and add it into an array of struct
package main import "fmt" type person struct { name string age int } var n int var p person var list []person func main() { //Enter your code here. Read input from STDIN. Print output to STDOUT fmt.Scanln(&n) for i := 0; i < n; i++ { var namez string var numberz int fmt.Scanln(&namez) fmt.Scanln(&numberz) list[i] = person{name: namez, age: numberz} } }