Front: Svelte.js (Sapper), API: Go (echo) I wanted to make an app Built using Docker.
To the point where Sapper and echo can be connected on the local host
In building this environment, Create with "Vue.js + Go language + Docker"! Image upload function implementation Hands-on was used as a reference.
Simple and easy to understand.
.
├── docker-compose.yml
└── server
npx degit "sveltejs/sapper-template#rollup" client
cd client
npm install
touch Dockerfile_develop
Although it is a Dockerfile, I want to prepare a Dockerfile for production in my case, so I name it Dockerfile_develop
.
If you don't need to divide it, or if it seems to fit in a multi-stage build, you can use one.
Dockerfile
FROM mhart/alpine-node:12
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
ENV HOST=0.0.0.0
EXPOSE 3000
docker-compose.yml
version: '3.8'
services:
client:
env_file: .env
build:
context: ./client
dockerfile: Dockerfile_${DOCKER_ENV} #Delete this line if you don't need it
ports:
- 3000:3000
tty: true
volumes:
- ./client:/app
command: npm run dev
touch .env
vim .env
DOCKER_ENV=develop
Let's see if Sapper starts at this stage
docker-compose up --build
cd server
touch Dockerfile
touch main.go
Dockerfile
FROM golang:1.15.2-alpine
WORKDIR /go/src/api
ADD . /go/src/api
ENV GO111MODULE=off
RUN apk update && apk add curl git
main.go
package main
import (
"net/http"
"github.com/labstack/echo"
)
func main() {
e := echo.New()
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World")
})
e.Logger.Fatal(e.Start(":8080"))
}
docker-compose.yml
version: '3.8'
...
server:
build: ./server
ports:
- 8080:8080
tty: true
volumes:
- ./server:/api
Launch echo's local server.
docker-compose up --build
docker-compose exec server /bin/ash
go get github.com/labstack/echo
go run main.go
If you can access localhost: 8080
, you're done.
Next, I want to go to the point where I put Gorm
, MySQL
Make with "Vue.js + Go language + Docker"! Image upload function implementation hands-on How to create a development environment for svelte Hello World Recipe
Recommended Posts