From 4edd5cb44e7b1e208aea113b0b9ee71f4bc3f82b Mon Sep 17 00:00:00 2001 From: vx3r Date: Wed, 5 Feb 2020 13:01:17 +0900 Subject: [PATCH] cd/cd docker build from Dockerfile --- .gitlab-ci.yml | 35 ++++++++++------------------------- Dockerfile | 25 ++++++++++++++++--------- Dockerfile.dev | 21 --------------------- 3 files changed, 26 insertions(+), 55 deletions(-) delete mode 100644 Dockerfile.dev diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2cbdf30..3559382 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,35 +1,20 @@ stages: - - build - - deploy + - build docker image + - push docker hub -build-back: - stage: build - image: golang:alpine +build: + stage: build docker image + image: docker:latest script: - - go build -o ${CI_PROJECT_NAME}-linux-amd64 - artifacts: - paths: - - ${CI_PROJECT_NAME}-linux-amd64 + - docker info + - docker build --network br_docker --tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} --tag ${CI_REGISTRY_IMAGE}:latest . -build-front: - stage: build - image: node:10-alpine - script: - - cd ./ui - - npm install - - npm run build - - cd .. - artifacts: - paths: - - ui/dist - -deploy: - stage: deploy +push: + stage: push docker hub image: docker:latest only: - master script: - - docker login -u ${CI_REGISTRY_USER} -p ${REGISTRY_PASSWORD} ${CI_REGISTRY} - - docker build --network br_docker --tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} --tag ${CI_REGISTRY_IMAGE}:latest . + - echo ${REGISTRY_PASSWORD} | docker login -u ${CI_REGISTRY_USER} --password-stdin ${CI_REGISTRY} - docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} - docker push ${CI_REGISTRY_IMAGE}:latest diff --git a/Dockerfile b/Dockerfile index ce67953..c4e3b6a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,21 @@ -FROM alpine - +FROM golang:alpine AS build-back 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 ui/dist ui/dist - -RUN chmod +x ./wg-gen-web-linux-amd64 -RUN apk update && apk --no-cache add wget ca-certificates - +RUN chmod +x ./wg-gen-web-linux +RUN apk add --no-cache ca-certificates EXPOSE 8080 -CMD ["/app/wg-gen-web-linux-amd64"] +CMD ["/app/wg-gen-web-linux"] \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev deleted file mode 100644 index 8b53d35..0000000 --- a/Dockerfile.dev +++ /dev/null @@ -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"] \ No newline at end of file