Clone your own web app on GitLab when building a Docker image

I created a Docker image that clones my own application from GitLab at build time. I will leave it as a memo.

Operating environment

Windows10 Pro GitLab

References

https://qiita.com/Brutus/items/da63d23be32d505409c6

procedure

Get Token for your account on GitLab

Press "Settings" in the upper right menu of GitLab. image.png

Press "Access Token" on the left menu. image.png

Enter any Token name in Name, check Scope api, and press "Create personal access token". image.png

If the creation is successful, the token will be displayed, so make a note of it. image.png

Build a Docker image

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! image.png

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

Clone your own web app on GitLab when building a Docker image
When building docker image with GitLab CI, wait until docker daemon starts
Deploy a Java web app on Heroku
Create a Docker container for your development web server in Ansible on MacOS
Build a streaming server on your iOS app
A memo when building a Rails 5.2 development environment using Docker Desktop + WSL2 on Windows 10 Home
Create a docker image that runs a simple Java app
A memorandum when installing Docker and building a Linux container
Register your own Docker image with ECR using AWS CLI
Solution when building Docker image stops at time zone selection
Measures for permissions when building MySQL with Docker on WSL2
Building a haskell environment with Docker + VS Code on Windows 10 Home
Create a Docker Image for redoc-cli and register it on Docker Hub
Run (provisionally) a Docker image with ShellCommandActivity on AWS Data Pipeline