0
0
mirror of https://github.com/vx3r/wg-gen-web.git synced 2024-12-19 00:23:27 +00:00

cd/cd docker build from Dockerfile

This commit is contained in:
vx3r 2020-02-05 13:01:17 +09:00
parent 26dec5ce7a
commit 4edd5cb44e
3 changed files with 26 additions and 55 deletions

View File

@ -1,35 +1,20 @@
stages: stages:
- build - build docker image
- deploy - push docker hub


build-back: build:
stage: build stage: build docker image
image: golang:alpine image: docker:latest
script: script:
- go build -o ${CI_PROJECT_NAME}-linux-amd64 - docker info
artifacts: - docker build --network br_docker --tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} --tag ${CI_REGISTRY_IMAGE}:latest .
paths:
- ${CI_PROJECT_NAME}-linux-amd64


build-front: push:
stage: build stage: push docker hub
image: node:10-alpine
script:
- cd ./ui
- npm install
- npm run build
- cd ..
artifacts:
paths:
- ui/dist

deploy:
stage: deploy
image: docker:latest image: docker:latest
only: only:
- master - master
script: script:
- docker login -u ${CI_REGISTRY_USER} -p ${REGISTRY_PASSWORD} ${CI_REGISTRY} - echo ${REGISTRY_PASSWORD} | docker login -u ${CI_REGISTRY_USER} --password-stdin ${CI_REGISTRY}
- docker build --network br_docker --tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} --tag ${CI_REGISTRY_IMAGE}:latest .
- docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} - docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}
- docker push ${CI_REGISTRY_IMAGE}:latest - docker push ${CI_REGISTRY_IMAGE}:latest

View File

@ -1,14 +1,21 @@
FROM alpine FROM golang:alpine AS build-back

WORKDIR /app WORKDIR /app
ADD . .
RUN go build -o wg-gen-web-linux


ADD wg-gen-web-linux-amd64 . FROM node:10-alpine as build-front
WORKDIR /app
ADD ui .
RUN npm install
RUN npm run build

FROM alpine
WORKDIR /app
COPY --from=build-back /app/wg-gen-web-linux .
COPY --from=build-front /app/dist ./ui/dist
ADD .env . ADD .env .
ADD ui/dist ui/dist RUN chmod +x ./wg-gen-web-linux

RUN apk add --no-cache ca-certificates
RUN chmod +x ./wg-gen-web-linux-amd64
RUN apk update && apk --no-cache add wget ca-certificates

EXPOSE 8080 EXPOSE 8080


CMD ["/app/wg-gen-web-linux-amd64"] CMD ["/app/wg-gen-web-linux"]

View File

@ -1,21 +0,0 @@
FROM golang:alpine AS build-back
WORKDIR /app
ADD . .
RUN go build -o wg-gen-web-linux-amd64

FROM node:10-alpine as build-front
WORKDIR /app
ADD ui .
RUN npm install
RUN npm run build

FROM alpine
WORKDIR /app
COPY --from=build-back /app/wg-gen-web-linux-amd64 .
COPY --from=build-front /app/dist ./ui/dist
ADD .env .
RUN chmod +x ./wg-gen-web-linux-amd64
RUN apk add --no-cache ca-certificates
EXPOSE 8080

CMD ["/app/wg-gen-web-linux-amd64"]