Pretty often developers facing situation, when you have your code locally and have to deploy it somehow on server. Sometimes you even have no pipeline ¯_(ツ)_/¯.
Lets deploy our app with DevOps Pass, Docker and SystemD.
You can do all following steps without even using console via DevOps Pass AI tool, which making DevOps simple as it should be (check video).
Docker'ize you app
Lets take some random Java Spring Boot app and Dockerize it.
For example - https://github.com/SimpleProgramming/simple-springboot-app
You can generate Dockerfile for Java Spring Boot (you can generate it in DevOps Pass):
FROM eclipse-temurin:17-jdk-focal as build
WORKDIR /build
COPY .mvn/ ./.mvn
COPY mvnw pom.xml ./
RUN ./mvnw dependency:go-offline
COPY . .
RUN ./mvnw package -DskipTests
FROM eclipse-temurin:17-jdk-alpine
WORKDIR /app
COPY --from=build /build/target/*.jar run.jar
ENTRYPOINT ["java", "-jar", "/app/run.jar"]
Build docker image with some tag:
# Build in app folder
docker build -t my-app:1.0.0 .
# Push to your registry or DockerHub https://hub.docker.com/signup
docker push my-app:1.0.0
Run application with SystemD
Now time to deploy your app, generate SystemD service file in DevOps Pass or use one below:
# app_springboot.service
[Unit]
Description=Sample springboot app
DefaultDependencies=no
After=network.target
[Service]
Type=simple
User=root
Group=root
Environment=PATH=$PATH:$HOME/.local/bin:$HOME/bin
WorkingDirectory=/tmp
ExecStart=/usr/bin/docker run --rm --name %n my-app:1.0.0
# Command to run before and after start, add "-" if command failures should be ignored, like "ExecStartPre=-docker pull nginx:latest"
# More details - https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html
# ExecStartPre=
# ExecStartPost=
ExecStop=/usr/bin/docker stop --time 10 %n
# Command to run before and after stop, add "-" if command failures should be ignored, like "ExecStopPost=-rm -Rf /var/log/app_logs/*"
# More details - https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html
# ExecStopPre=
# ExecStopPost=
# Reload command
# More details - https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html
# ExecReload=kill -HUP $MAINPID
TimeoutStartSec=0
RemainAfterExit=yes
Restart=always
[Install]
WantedBy=default.target
Now you can deploy and start your app on server:
# copy your service
scp app_springboot.service user@host:/etc/systemd/system/
# reload systemd
systemctl daemon-reload
# enable service
systemctl enable app_springboot.service
# start your app
systemctl start app_springboot.service
# check your app status
systemctl status app_springboot.service
# Check app logs
journalctl -u app_springboot.service
Top comments (0)