I created a Docker image that clones my own application from GitLab at build time. I will leave it as a memo.
Windows10 Pro GitLab
https://qiita.com/Brutus/items/da63d23be32d505409c6
Press "Settings" in the upper right menu of GitLab.
Press "Access Token" on the left menu.
Enter any Token name in Name, check Scope api, and press "Create personal access token".
If the creation is successful, the token will be displayed, so make a note of it.
Create Dockerfile as follows.
Dockerfile
#I wanted to put the node express app, so I used the node image
FROM node:10.12
#Specify working directory
WORKDIR /src
#Describe the creator information
LABEL maintainer="y.matsumoto <[email protected]>"
# -Specify the directory to clone with the C option. https://oauth2:[Token obtained from GitLab]@gitlab.com/[Project name]/[Repository name].git syntax of URL
RUN git -C / clone chat https://oauth2:[Token obtained from GitLab]@gitlab.com/[Project name]/[Repository name].git
#Since the executable file system of express is in the app directory, copy it to the working directory
RUN cp -r /[Repository name]/app/* /src
#Delete unnecessary files after cloning
RUN rm -rf /[Repository name]
#App package in working directory.Since json is copied, npm install can be executed as it is
RUN npm install
#Set the server to start when the container runs
CMD npm start
Execute the following command in the directory containing the Dockerfile to execute the build & container.
docker image build . --tag [Arbitrary tag name]
docker container run -d -p 3000:3000 [Specified tag name]
When I accessed it with a browser, it started up without any problems!
that's all.
I created a docker image that pulled the latest version of my own application at build time, I would like to push it to the registry later and aim for a form that can be used by pulling it with Kubernetes.
If you have any suggestions, please do not hesitate to contact us!
Recommended Posts