podman machine init fails with unhelpful output - github-actions

I am running the command
podman machine init
in the /entrypoint.sh script which I reference in my Dockerfile:
# Container image that runs your code
FROM ubuntu:latest
# Copies your code file from your action repository to the filesystem path `/` of the container
COPY entrypoint.sh /entrypoint.sh
RUN apt-get update -y
RUN apt-get install -y git gcc python3-dev musl-dev libffi-dev podman
# Code file to execute when the docker container starts up (`entrypoint.sh`)
ENTRYPOINT ["/entrypoint.sh"]
The Dockerfile and the entrypoint.sh scripts are in my github repo where I have github actions configured. The problem I see my my log output from the Github action is this ...
2022-11-29T04:56:58.6855699Z + podman machine init
2022-11-29T04:56:59.1867174Z Downloading VM image: fedora-coreos-37.20221106.2.1-qemu.x8…
2022-11-29T04:56:59.3660034Z [1A[JDownloading VM image: fedora-coreos-37.20221106.2.1-qemu.x8…
...
2022-11-29T04:57:06.5082410Z [1A[JDownloading VM image: fedora-coreos-37.20221106.2.1-qemu.x8…
2022-11-29T04:57:06.9133659Z Extracting compressed file
2022-11-29T04:57:36.0586753Z Error: exit status 1
Extracting compressed file? Did I run out of disk space? What? I am not even sure where to begin to debug this.

Related

Create a Dockerfile with ubuntu image and run mysql in it

I am trying to set up a Dockerfile with an ubuntu image that runs a mysql server (I know I should use the mysql image instead, but I need to do it this way for an assignment). I am having a lot of trouble designing the Dockerfile. My Dockerfile looks like this right now:
FROM ubuntu:latest
EXPOSE 3306
VOLUME [ "/var/lib/mysql" ]
RUN apt update && \
apt install -y mysql-server && \
apt-get install -y gosu
ENV MYSQL_ROOT_PASSWORD=secret
COPY ./wordpress.sql /docker-entrypoint-initdb.d/
COPY ./docker-entrypoint.sh /usr/local/bin/
COPY ./entrypoint.sh /
RUN chmod +x entrypoint.sh && \
chmod +x /docker-entrypoint-initdb.d/wordpress.sql && \
chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
CMD [ "mysqld" ]
(I am running docker build -t sql . to build the image, and docker run --name sql_cont -v sql_vol:/var/lib/mysql sql_img to run the container)
I have a folder where I have the docker-entrypoint.sh file and the entrypoint.sh file, because when I install mysql-server, these files are not created by default as If I was just using the mysql docker image.
I just need a Dockerfile from an ubuntu image that runs mysql and just stays waiting ready for connections, so, If anybody know how to refactor this Dockerfile or just give me the answer I'd much appreciate it.
If I got What is the difference between CMD and ENTRYPOINT in a Dockerfile? right, the argument in CMD will be passed to the ENTRYPOINT. Don’t know about your ENTRYPOINT script, but I expect it to just ignore parameters.
I would suggest to:
not replace the default ENTRYPOINT (defaults to /bin/sh -c)
start the docker-entrypoint.sh from CMD
Append mysqld to docker-ENTRYPOINT.sh

Crontab in Docker with flask application

I'm trying to create cronjob within the docker container, But the it doesn't work. Below is my code
Dockerfile
FROM python:3
LABEL image for a very management application
# We copy just the requirements.txt first to leverage Docker cache
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN apt-get install -y default-libmysqlclient-dev
RUN pip3 install -r requirements.txt
RUN apt-get update && apt-get -y install cron
RUN touch /var/log/cron.log
COPY crontab /etc/cron.d/cjob
RUN chmod 0644 /etc/cron.d/cjob
ENV PYTHONUNBUFFERED 1
CMD cron -f
EXPOSE 5000
COPY . .
CMD ["cron", "-f"]
CMD [ "python3", "app.py" ]
crontab
*/5 * * * * root /test.py >> /logfile
test.py
from datetime import datetime
print("Our test works at", datetime.now())
I'm tring to run cronjob with the
docker-compose up
Is anything wrong i'm doing, Is their any other way for cronjob to work. Please can anyone help me. Thank you all
Since you can mainly run one CMD you will need to use the ENTRYPOINT directive. I can give you an example of how I made it work.
The theory behind the solution is that in the base image during build time you prepare all the necessary documents:
copy in the crontab file and apply it
Copy in the additional launch script
set ENTRYPOINT to the launch script
run CMD and start your app
Example:
COPY token-renewal-cron /etc/cron.d/token-renewal-cron
RUN crontab /etc/cron.d/token-renewal-cron
where crontab logic is inside token-renewal-cron
Then you need to copy the launch script into the /usr/local/bin/ directory
COPY launch.sh /usr/local/bin/launch.sh
RUN chmod 0777 /usr/local/bin/launch.sh #0777 as long as it works for POC :)
Where in our case launch.sh contains:
cron # this starts the cron process
TMP # some commands we need to run next to cron command (we prepare app env here)
# Append CMD from Dockerfile NOTE this is important so you can then use CMD after ENTRYPOINT inside DOCKERFILE
exec "$#"
Then at the end of the DOCKERFILE you just prepare ENTRYPOINT and CMD commands
#Launch our entrypoint script
ENTRYPOINT ["launch.sh"]
#Launch our application
CMD ["dotnet", "APPLICATION.dll"]

Reduce build time in GitOps by using Docker image layers from previous build with Azure Registry

I'm building a Docker Image on Pull Requests in my Github Actions setup. The images are built and pushed to Azure Container Registry. Often, it's only a small update in the code, and if I could reuse the layers from the previous build (pushed to ACR), I could save a lot of time.
As shown in Dockerfile, yarn install could be skipped, since new changes occur in the COPY statement below it only:
FROM node:16
# create dirs and chown
RUN mkdir -p /usr/src/node-app && chown -R node:node /usr/src/node-app
WORKDIR /usr/src/node-app
COPY package.json yarn.lock tsconfig.json ./
USER node
# install node modules
RUN yarn install --pure-lockfile
# ensure ownership
COPY --chown=node:node . .
# set default env
RUN mv .env.example .env
EXPOSE 3001
# entrypoint is node
# see https://github.com/nodejs/docker-node/blob/main/docker-entrypoint.sh
# default command: prod start
CMD ["yarn", "start"]
How can I download the previous image from ACR and use the layers there? Simply downloading the previous image (with different tag) does not seem to work.
You need to provide the --cache-from flag to the docker build command if you want to use the downloaded image as cache source.
https://docs.docker.com/engine/reference/commandline/build/#options

How do I build a custom Docker image that installs MySQL and configure Jib to use it as the base image for my Java Application?

Docker newbie here. I'm trying to mount a docker image of my Java App made with Jib on GCE, and hook it up to CloudSQL. However, because GCE makes the docker image use a Container-Optimized boot disk, when I SSH into the instance to try to hook it up to MySQL, I can't install mysql due to 'apt-get not found'.
I read that I could "build a custom image and configure Jib to use it as the base image" in order to have access to apt-get, but I can't seem to find any resources on how to do this.
I tried going the alpine jdk route + using apk instead of apt-get, but someone told me not to use alpine jdk as I will run into problems later.
I already have this set up in my build.gradle:
jib {
from {
image = 'order-routing-helper-image'
}
to {
image = 'gcr.io/myimage'
}
}
EDIT: DOCKERFILE:
FROM openjdk:11
VOLUME /tmp
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.mygroup.myapp.OrderRoutingApplication"]
but I don't have a order-routing-helper-image anywhere, I just know I need that line.
If I run gradle jib, and then mount the new image on GCE and SSH into it, I am able to run "sudo apt-get install mysql-client". Right now I'm getting "apt-get: not found".
To add MySQL in Docker image, you to run the update first then add MySQL.
FROM openjdk:11
VOLUME /tmp
RUN apt update && apt install mysql-server -y
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.mygroup.myapp.OrderRoutingApplication"]

Run statsd as a daemon on EC2 instances programatically

EDIT: My goal is to be able to emit metrics from my spring-boot application and have them sent to a Graphite server. For that I am trying to set up statsd. If you can suggest a cleaner approach, that would be better.
I have a Beanstalk application which requires statsd to run as a background process. I was able to specify commands and packages through ebextensions config file as follows:
packages:
yum:
git: []
commands:
01_nodejs_install:
command: sudo yum -y install nodejs npm --enablerepo=epel
ignoreErrors: true
02_mkdir_statsd:
command: mkdir /home/ec2-user/statsd
03_fetch_statsd:
command: git clone https://github.com/etsy/statsd.git /home/ec2-user/statsd
ignoreErrors: true
04_run_statsd:
command: node stats.js exampleConfig.js
cwd: /home/ec2-user/statsd
When I try to deploy the application to a new environment, the EC2 node never comes up fully. I logged in to check what might be going on and noticed in /var/log/cfn-init.log that 01_nodejs_install, 02_mkdir_statsd and 03_fetch_statsd were executed successfully. So I guess the system was stuck on the fourth command (04_run_statsd).
2016-05-24 01:25:09,769 [INFO] Yum installed [u'git']
2016-05-24 01:25:37,751 [INFO] Command 01_nodejs_install succeeded
2016-05-24 01:25:37,755 [INFO] Command 02_mkdir_statsd succeeded
2016-05-24 01:25:38,700 [INFO] Command 03_fetch_statsd succeeded
cfn-init.log (END)
I need help with the following:
If there is a better way to install and run statsd while instantiating an environment, I would appreciate if you could provide details on that approach. This current scheme seems hacky.
If this is the approach I need to stick with, how can I run the fourth command so that statsd can be run as a background process?
Tried a few things and found that the following ebextensions configs work:
packages:
yum:
git: []
commands:
01_nodejs_install:
command: sudo yum -y install nodejs npm --enablerepo=epel
ignoreErrors: true
02_mkdir_statsd:
command: mkdir /home/ec2-user/statsd
03_fetch_statsd:
command: git clone https://github.com/etsy/statsd.git /home/ec2-user/statsd
ignoreErrors: true
04_change_config:
command: cat exampleConfig.js | sed 's/2003/<graphite server port>/g' | sed 's/graphite.example.com/my.graphite.server.hostname/g' > config.js
cwd: /home/ec2-user/statsd
05_run_statsd:
command: setsid node stats.js config.js >/dev/null 2>&1 < /dev/null &
cwd: /home/ec2-user/statsd
Note that I added another command (04_change_config) so that I may configure my own Graphite server and port in statsd configs. This change is not needed to address the original question, though.
The actual run command uses setsid to run the command as a daemon.