Skip to content

Commit

Permalink
feat:docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
0xzkm committed Mar 27, 2024
1 parent 5047788 commit 1ad1cf5
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 6 deletions.
54 changes: 54 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# base image
FROM --platform=linux/amd64 ubuntu:latest

# install necessary packages
RUN apt-get update && apt-get install -y \
curl \
gnupg \
lsb-release \
apt-transport-https \
ca-certificates

# add Golang offical GPG key
RUN curl -sSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

RUN apt-get install wget

RUN wget https://go.dev/dl/go1.22.1.linux-amd64.tar.gz

RUN rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.1.linux-amd64.tar.gz

# setup Golang env
ENV GOPATH /go
ENV GOROOT /usr/local/go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

# install MySQL
RUN apt-get update && apt-get install -y mysql-server && apt-get install -y mysql-client

# set up MySQL root password
ENV MYSQL_ROOT_PASSWORD 123456

WORKDIR /app

COPY my.cnf /etc/mysql/mysql.conf.d/mysqld.cnf
COPY storage/migrations/db.sql /SQL
RUN mysqld_safe & until mysqladmin ping; do sleep 1; done && \
mysql -e "SOURCE /SQL;" && mysqladmin -u root password 123456
RUN service mysql restart

COPY . .
ENV GOOS linux
ENV GOARCH amd64
RUN GOOS=linux GOARCH=amd64 go build -o /app/server/server ./server
RUN touch /app/server/server.log
RUN chmod a+x /app/server/server
RUN echo "nohup /app/server/server -prover_cycle_time=15000 -log_level=4 > /app/server/server.log 2>&1 &" > /app/start.sh
RUN chmod a+x /app/start.sh

# expose mysql,server port
EXPOSE 3306 50051

# Set the command to be executed when the container starts
CMD ["mysqld"]
#CMD ["nohup /app/server/server -prover_cycle_time=15000 -log_level=4 > /app/server/server.log 2>&1 &"]
78 changes: 78 additions & 0 deletions my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# The MySQL database server configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld]
#
# * Basic Settings
#
user = mysql
#pid-file = /run/mysqld/mysqld.pid
#socket = /run/mysqld/mysqld.sock
# port = 3306
# datadir = /var/lib/mysql


# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
mysqlx-bind-address = 0.0.0.0
#
# * Fine Tuning
#
key_buffer_size = 16M
# max_allowed_packet = 64M
# thread_stack = 256K

# thread_cache_size = -1

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP

# max_connections = 151

# table_open_cache = 4000

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
#
# Log all queries
# Be aware that this log type is a performance killer.
# general_log_file = /var/log/mysql/query.log
# general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
# slow_query_log = 1
# slow_query_log_file = /var/log/mysql/mysql-slow.log
# long_query_time = 2
# log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
# server-id = 1
# log_bin = /var/log/mysql/mysql-bin.log
# binlog_expire_logs_seconds = 2592000
max_binlog_size = 100M
# binlog_do_db = include_database_name
# binlog_ignore_db = include_database_name
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func logger() *log.Entry {
}

func main() {
lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", *port))
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
Expand Down
15 changes: 10 additions & 5 deletions storage/migrations/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ CREATE DATABASE IF NOT EXISTS zkm;

use zkm;

DROP TABLE IF EXISTS prover_job_queue;
CREATE TABLE prover_job_queue
CREATE TABLE IF NOT EXISTS prover_job_queue
(
id serial primary key,
job_status int not null,
Expand All @@ -22,13 +21,19 @@ CREATE TABLE prover_job_queue
INDEX job_type(job_type(255))
);

DROP TABLE IF EXISTS proofs;
CREATE TABLE proofs
CREATE TABLE IF NOT EXISTS proofs
(
id serial primary key,
proof_id text not null,
computed_request_id text not null,
proof blob not null,
created_at timestamp not null default now(),
INDEX proof_id_req_id(proof_id(255), computed_request_id(255))
);
);

use mysql;

ALTER user 'root'@'localhost' IDENTIFIED BY '123456';
UPDATE user SET plugin='mysql_native_password' WHERE User='root';

FLUSH PRIVILEGES;

0 comments on commit 1ad1cf5

Please sign in to comment.