Compare commits
5 Commits
0caae36787
...
1c88c9cfb5
Author | SHA1 | Date |
---|---|---|
Quentin McGaw (desktop) | 1c88c9cfb5 | 3 years ago |
Quentin McGaw (desktop) | ba9c42d4c7 | 3 years ago |
Quentin McGaw (desktop) | f7e120cddd | 3 years ago |
Quentin McGaw (desktop) | 84ec3c82ad | 3 years ago |
Quentin McGaw (desktop) | 9698606fe6 | 3 years ago |
@ -0,0 +1,5 @@
|
||||
.dockerignore
|
||||
devcontainer.json
|
||||
docker-compose.yml
|
||||
Dockerfile
|
||||
README.md
|
@ -0,0 +1 @@
|
||||
FROM qmcgaw/godevcontainer
|
@ -0,0 +1,70 @@
|
||||
# Development container
|
||||
|
||||
Development container that can be used with VSCode.
|
||||
|
||||
It works on Linux, Windows and OSX.
|
||||
|
||||
## Requirements
|
||||
|
||||
- [VS code](https://code.visualstudio.com/download) installed
|
||||
- [VS code remote containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) installed
|
||||
- [Docker](https://www.docker.com/products/docker-desktop) installed and running
|
||||
- [Docker Compose](https://docs.docker.com/compose/install/) installed
|
||||
|
||||
## Setup
|
||||
|
||||
1. Create the following files on your host if you don't have them:
|
||||
|
||||
```sh
|
||||
touch ~/.gitconfig ~/.zsh_history
|
||||
```
|
||||
|
||||
Note that the development container will create the empty directories `~/.docker`, `~/.ssh` and `~/.kube` if you don't have them.
|
||||
|
||||
1. **For Docker on OSX or Windows without WSL**: ensure your home directory `~` is accessible by Docker.
|
||||
1. **For Docker on Windows without WSL:** if you want to use SSH keys, bind mount your host `~/.ssh` to `/tmp/.ssh` instead of `~/.ssh` by changing the `volumes` section in the [docker-compose.yml](docker-compose.yml).
|
||||
1. Open the command palette in Visual Studio Code (CTRL+SHIFT+P).
|
||||
1. Select `Remote-Containers: Open Folder in Container...` and choose the project directory.
|
||||
|
||||
## Customization
|
||||
|
||||
### Customize the image
|
||||
|
||||
You can make changes to the [Dockerfile](Dockerfile) and then rebuild the image. For example, your Dockerfile could be:
|
||||
|
||||
```Dockerfile
|
||||
FROM qmcgaw/godevcontainer
|
||||
RUN apk add curl
|
||||
```
|
||||
|
||||
To rebuild the image, either:
|
||||
|
||||
- With VSCode through the command palette, select `Remote-Containers: Rebuild and reopen in container`
|
||||
- With a terminal, go to this directory and `docker-compose build`
|
||||
|
||||
### Customize VS code settings
|
||||
|
||||
You can customize **settings** and **extensions** in the [devcontainer.json](devcontainer.json) definition file.
|
||||
|
||||
### Entrypoint script
|
||||
|
||||
You can bind mount a shell script to `/home/vscode/.welcome.sh` to replace the [current welcome script](shell/.welcome.sh).
|
||||
|
||||
### Publish a port
|
||||
|
||||
To access a port from your host to your development container, publish a port in [docker-compose.yml](docker-compose.yml). You can also now do it directly with VSCode without restarting the container.
|
||||
|
||||
### Run other services
|
||||
|
||||
1. Modify [docker-compose.yml](docker-compose.yml) to launch other services at the same time as this development container, such as a test database:
|
||||
|
||||
```yml
|
||||
database:
|
||||
image: postgres
|
||||
restart: always
|
||||
environment:
|
||||
POSTGRES_PASSWORD: password
|
||||
```
|
||||
|
||||
1. In [devcontainer.json](devcontainer.json), change the line `"runServices": ["vscode"],` to `"runServices": ["vscode", "database"],`.
|
||||
1. In the VS code command palette, rebuild the container.
|
@ -1,64 +1,85 @@
|
||||
ARG ALPINE_VERSION=3.12
|
||||
ARG GO_VERSION=1.14
|
||||
ARG STACKEDIT_VERSION=v5.14.5
|
||||
|
||||
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS server
|
||||
RUN apk --update add git
|
||||
ENV CGO_ENABLED=0
|
||||
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s ${GOLANGCI_LINT_VERSION}
|
||||
WORKDIR /tmp/gobuild
|
||||
COPY .golangci.yml .
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download 2>&1
|
||||
COPY main.go ./
|
||||
#RUN go test -v -race ./...
|
||||
RUN golangci-lint run --timeout=10m
|
||||
RUN go build -ldflags="-s -w" -o app main.go
|
||||
|
||||
FROM --platform=amd64 alpine:${ALPINE_VERSION} AS stackedit
|
||||
ARG STACKEDIT_VERSION
|
||||
WORKDIR /stackedit
|
||||
RUN apk add -q --progress --update --no-cache git npm
|
||||
RUN git clone --branch ${STACKEDIT_VERSION} --single-branch --depth 1 https://github.com/benweet/stackedit.git . &> /dev/null
|
||||
RUN npm install --only=prod
|
||||
RUN npm audit fix
|
||||
ENV NODE_ENV=production
|
||||
RUN sed -i "s/assetsPublicPath: '\/',/assetsPublicPath: '.\/',/g" config/index.js
|
||||
RUN npm run build
|
||||
|
||||
FROM scratch AS final
|
||||
ARG BUILD_DATE
|
||||
ARG VCS_REF
|
||||
ARG STACKEDIT_VERSION
|
||||
LABEL \
|
||||
org.opencontainers.image.authors="quentin.mcgaw@gmail.com" \
|
||||
org.opencontainers.image.created=$BUILD_DATE \
|
||||
org.opencontainers.image.version=$STACKEDIT_VERSION \
|
||||
org.opencontainers.image.revision=$VCS_REF \
|
||||
org.opencontainers.image.url="https://github.com/qdm12/stackedit-docker" \
|
||||
org.opencontainers.image.documentation="https://github.com/qdm12/stackedit-docker/blob/master/README.md" \
|
||||
org.opencontainers.image.source="https://github.com/qdm12/stackedit-docker" \
|
||||
org.opencontainers.image.title="stackedit-docker" \
|
||||
org.opencontainers.image.description="StackEdit server in a lightweight Docker container"
|
||||
EXPOSE 8000
|
||||
HEALTHCHECK --start-period=1s --interval=100s --timeout=2s --retries=1 CMD ["/server","healthcheck"]
|
||||
USER 1000
|
||||
ENTRYPOINT ["/server"]
|
||||
ENV \
|
||||
LISTENING_PORT=8000 \
|
||||
ROOT_URL=/ \
|
||||
NODE_ENV=production \
|
||||
PANDOC_PATH=pandoc \
|
||||
WKHTMLTOPDF_PATH=wkhtmltopdf \
|
||||
USER_BUCKET_NAME=stackedit-users \
|
||||
PAYPAL_RECEIVER_EMAIL= \
|
||||
DROPBOX_APP_KEY= \
|
||||
DROPBOX_APP_KEY_FULL= \
|
||||
GITHUB_CLIENT_ID= \
|
||||
GITHUB_CLIENT_SECRET= \
|
||||
GOOGLE_CLIENT_ID= \
|
||||
GOOGLE_API_KEY= \
|
||||
WORDPRESS_CLIENT_ID=
|
||||
COPY --from=stackedit --chown=1000 /stackedit/dist /html/dist
|
||||
COPY --from=stackedit --chown=1000 /stackedit/static /html/static
|
||||
COPY --from=server --chown=1000 /tmp/gobuild/app /server
|
||||
# Sets linux/amd64 in case it's not injected by older Docker versions
|
||||
ARG BUILDPLATFORM=linux/amd64
|
||||
|
||||
ARG ALPINE_VERSION=3.14
|
||||
ARG STACKEDIT_VERSION=v5.14.10
|
||||
ARG GO_VERSION=1.17
|
||||
ARG XCPUTRANSLATE_VERSION=v0.6.0
|
||||
ARG GOLANGCI_LINT_VERSION=v1.42.1
|
||||
|
||||
FROM --platform=${BUILDPLATFORM} qmcgaw/xcputranslate:${XCPUTRANSLATE_VERSION} AS xcputranslate
|
||||
FROM --platform=${BUILDPLATFORM} qmcgaw/binpot:golangci-lint-${GOLANGCI_LINT_VERSION} AS golangci-lint
|
||||
|
||||
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
|
||||
ENV CGO_ENABLED=0
|
||||
WORKDIR /tmp/gobuild
|
||||
RUN apk --update add git g++
|
||||
COPY --from=xcputranslate /xcputranslate /usr/local/bin/xcputranslate
|
||||
COPY --from=golangci-lint /bin /go/bin/golangci-lint
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY main.go .
|
||||
|
||||
FROM base AS lint
|
||||
COPY .golangci.yml ./
|
||||
RUN golangci-lint run --timeout=10m
|
||||
|
||||
FROM base AS server
|
||||
ARG TARGETPLATFORM
|
||||
ARG VERSION=unknown
|
||||
ARG CREATED="an unknown date"
|
||||
ARG COMMIT=unknown
|
||||
RUN GOARCH="$(xcputranslate translate -targetplatform=${TARGETPLATFORM} -field arch)" \
|
||||
GOARM="$(xcputranslate translate -targetplatform=${TARGETPLATFORM} -field arm)" \
|
||||
go build -trimpath -ldflags="-s -w \
|
||||
-X 'main.version=$VERSION' \
|
||||
-X 'main.buildDate=$CREATED' \
|
||||
-X 'main.commit=$COMMIT' \
|
||||
" -o app main.go
|
||||
|
||||
FROM --platform=amd64 alpine:${ALPINE_VERSION} AS stackedit
|
||||
ARG STACKEDIT_VERSION
|
||||
WORKDIR /stackedit
|
||||
RUN apk add -q --progress --update --no-cache git npm python3 make g++
|
||||
RUN git clone --branch ${STACKEDIT_VERSION} --single-branch --depth 1 https://github.com/benweet/stackedit.git . &> /dev/null
|
||||
RUN npm install
|
||||
ENV NODE_ENV=production
|
||||
RUN sed -i "s/assetsPublicPath: '\/',/assetsPublicPath: '.\/',/g" config/index.js
|
||||
RUN npm run build
|
||||
|
||||
FROM scratch AS final
|
||||
ARG CREATED
|
||||
ARG COMMIT
|
||||
ARG STACKEDIT_VERSION
|
||||
LABEL \
|
||||
org.opencontainers.image.authors="quentin.mcgaw@gmail.com" \
|
||||
org.opencontainers.image.created=$CREATED \
|
||||
org.opencontainers.image.version=$STACKEDIT_VERSION \
|
||||
org.opencontainers.image.revision=$COMMIT \
|
||||
org.opencontainers.image.url="https://github.com/qdm12/stackedit-docker" \
|
||||
org.opencontainers.image.documentation="https://github.com/qdm12/stackedit-docker/blob/master/README.md" \
|
||||
org.opencontainers.image.source="https://github.com/qdm12/stackedit-docker" \
|
||||
org.opencontainers.image.title="stackedit-docker" \
|
||||
org.opencontainers.image.description="StackEdit server in a lightweight Docker container"
|
||||
EXPOSE 8000
|
||||
HEALTHCHECK --start-period=1s --interval=100s --timeout=2s --retries=1 CMD ["/server","healthcheck"]
|
||||
USER 1000
|
||||
ENTRYPOINT ["/server"]
|
||||
ENV \
|
||||
LISTENING_PORT=8000 \
|
||||
ROOT_URL=/ \
|
||||
NODE_ENV=production \
|
||||
PANDOC_PATH=pandoc \
|
||||
WKHTMLTOPDF_PATH=wkhtmltopdf \
|
||||
USER_BUCKET_NAME=stackedit-users \
|
||||
PAYPAL_RECEIVER_EMAIL= \
|
||||
DROPBOX_APP_KEY= \
|
||||
DROPBOX_APP_KEY_FULL= \
|
||||
GITHUB_CLIENT_ID= \
|
||||
GITHUB_CLIENT_SECRET= \
|
||||
GOOGLE_CLIENT_ID= \
|
||||
GOOGLE_API_KEY= \
|
||||
WORDPRESS_CLIENT_ID=
|
||||
COPY --from=stackedit --chown=1000 /stackedit/dist /html/dist
|
||||
COPY --from=stackedit --chown=1000 /stackedit/static /html/static
|
||||
COPY --from=server --chown=1000 /tmp/gobuild/app /server
|
||||
|
Loading…
Reference in new issue