HomeAboutPostsTagsProjectsRSS

Updated
Words412
TagsRead2 minutes

When building Docker images, it is common to configure Git within the image using commands like git config --global user.name and git config --global user.email. These commands update the global Git configuration for the user during the image build process. However, when running git commit inside a container that is spawned from the image, you may encounter a “please tell me who you are” error. This error occurs because the Git configuration set during the build process does not persist in the container.

The Issue

The git config --global command updates the global Git configuration for the user running the command. By default, the configuration is stored in a .gitconfig file located in the home directory of the user. When you add the git config commands to your Dockerfile, they only affect the image build process and do not persist when a container is created.

Solution Methods

Method 1: Set Git Config at Runtime

One way to resolve this issue is by setting the Git configuration within the container at runtime. This can be done manually or by adding the commands to a startup script. For example, you can run the following commands when starting the container:

git config --global user.name "Your Name"
git config --global user.email "email@example.com"

By setting the Git configuration at runtime, it ensures that the configuration is applied consistently whenever a container is started.

Method 2: Copy a Prepared .gitconfig File

Another approach is to prepare a .gitconfig file on your host system with the desired settings and then copy it into the Docker image. This method allows you to define the Git configuration outside of the Docker build process.

To do this, create a .gitconfig file on your host system with the desired Git settings. For example:

[user]
    name = Your Name
    email = email@example.com

Next, include the following line in your Dockerfile:

COPY .gitconfig /root/.gitconfig

This line copies the .gitconfig file from the host system into the /root/.gitconfig path within the image. When a container is created from the image, it will include the copied .gitconfig file, ensuring that the Git configuration is persisted.

Conclusion

When using Git within Docker containers, it is important to ensure that the Git configuration persists across container runs. This can be achieved by setting the Git configuration at runtime or by copying a prepared .gitconfig file into the container. By following these approaches, you can avoid the “please tell me who you are” error and have consistent Git configurations within your Docker containers.

Updated
Words393
TagsRead2 minutes

Enabling APIs

To get started with setting up a CI/CD pipeline using Google Cloud Build and GitHub, the first step is to enable the necessary APIs in your Google Cloud Console. Specifically, you need to enable the Cloud Build API and the Cloud Run API. This can be done easily by navigating to the APIs & Services section in the Google Cloud Console and enabling the respective APIs.

Connecting GitHub Repository

Once the APIs are enabled, the next step is to connect your GitHub repository to Google Cloud Build. To do this, navigate to the Cloud Build dashboard in the Google Cloud Console. From there, go to the “Triggers” section and click on “Connect Repository”. Choose GitHub as the source and authenticate with your GitHub account. After authentication, select the repository you want to connect to Google Cloud Build.

Creating Build Trigger

After successfully connecting your GitHub repository, you need to create a build trigger. A build trigger defines the conditions under which a build should be triggered, such as when changes are pushed to a specific branch or tag. To create a build trigger, specify the branch or tag that should trigger the build and define the build configuration. The build configuration can be defined using a cloudbuild.yaml file in your repository. This file specifies the steps that should be performed during the build process.

Here’s a sample cloudbuild.yaml file that builds a Docker image and deploys it to Cloud Run:

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/$PROJECT_ID/my-image', '.']
- name: 'gcr.io/cloud-builders/gcloud'
  args: ['run', 'deploy', 'my-service', '--image', 'gcr.io/$PROJECT_ID/my-image', '--platform', 'managed']

Make sure to customize this file according to your project’s specific needs, such as the image name, service name, and any additional build steps required.

Granting Permissions to Cloud Build Service Account

Finally, in order for Cloud Build to have the necessary permissions to access and deploy the service to Cloud Run, you need to grant the Cloud Build service account the “Cloud Run Admin” role. This role provides the necessary permissions for the build process to deploy the service to Cloud Run successfully.

By following these steps, you can set up a CI/CD pipeline with Google Cloud Build and GitHub, automating the build and deployment process whenever changes are pushed to your GitHub repository. This ensures a seamless and efficient development workflow, allowing you to focus on writing code and delivering your application quickly and reliably.

Updated
Words276
TagsRead1 minute

As of the time of writing, the current version of A-Shell is 1.12.1.

Passing Python Files to A-Shell

When using the iOS shortcut action A-Shell , the Put File action does not provide an option to specify the filename. Instead, it automatically names the file based on the first line of th content, excluding special symbols.

Base on this observation we can use the first line to specify filename and modify it after the file creation.

Let’s consider the following content.

getgif
import sys

if __name__ == "__main__":
    # print the first command line argument
    print(sys.argv[1])

it will be named getgif.txt after being passed from the “Text” action into A-Shell put file action

Removing the First Line with Sed

To remove the first line of a file (in this case, getgif.txt), we can utilize the Execute Command shortcut action in A-Shell. The command we can use is

sed -i '' '1d' getgif.txt

Executing the Python Script

Once we have removed the first line of the file, we can proceed to execute the Python script within A-Shell using Execute Command

python getgif.txt "hello"