Cannot use gvenzl/oracle-free oracle free image in Github actions

I have a github actions repository and I would like it to connect with an Oracle database, containerised using Oracle Database Free Container / Docker images image.
I would like to perform additional initialization of the database using a *.sql file under /container-entrypoint-initdb.d, as indicated in the image description.
However, I get the following error when I try to build it. More specifically, I get the error:

Error 45 initializing SQL*Plus

My workflow.yml contains:

services:

      # Oracle service (label used to access the service container)
      oracle:

        # Docker Hub image (feel free to change the tag "latest" to any other available one)
        image: gvenzl/oracle-free:latest

        # Provide passwords and other environment variables to container
        env:
          ORACLE_RANDOM_PASSWORD: true
          APP_USER: my_user
          APP_USER_PASSWORD: password_i_should_change

        # Forward Oracle port
        ports:
          - 1521:1521

        # Provide healthcheck script options for startup
        options: >-
          --health-cmd healthcheck.sh
          --health-interval 10s
          --health-timeout 5s
          --health-retries 10
        volumes:
          - my-init.sql:/container-entrypoint-initdb.d/my-init.sql:ro

As stated in the image documentation.

On the other hand, the file /container-entrypoint-initdb.d/my-init.sql, included in the repository’s root has the following lines:

alter session set container=freepdb1;
CREATE USER TEST IDENTIFIED BY test QUOTA UNLIMITED ON USERS;
GRANT CONNECT, RESOURCE TO TEST;

I do not find the problem. Any help is welcome.

Thanks

UPDATE. Following the first suggestion given by Azzem, I have tried with:

name: Build and test of Java Project
 
on: [push]
 
jobs:
 build:
   runs-on: ubuntu-latest
   timeout-minutes: 6
   services:

      # Oracle service (label used to access the service container)
      oracle:

        # Docker Hub image (feel free to change the tag "latest" to any other available one)
        image: gvenzl/oracle-free:latest
       
        # Provide passwords and other environment variables to container
        env:
          ORACLE_RANDOM_PASSWORD: true
          APP_USER: my_user
          APP_USER_PASSWORD: password_i_should_change

        # Forward Oracle port
        ports:
          - 1521:1521

        # Provide healthcheck script options for startup
        options: >-
          --name oracle
          --health-cmd healthcheck.sh
          --health-interval 10s
          --health-timeout 5s
          --health-retries 10
        # volumes:
        #   - my-init.sql:/container-entrypoint-initdb.d/my-init.sql:ro
   steps:
     - uses: actions/checkout@v2
     - name: Set up JDK 21
       uses: actions/setup-java@v1
       with:
         java-version: 21
     - name: Setup timezone
       uses: zcong1993/setup-timezone@master
       with:
          timezone: Europe/Madrid
     - name: Restart_container
        # Restart container after volumes have been checked out
       uses: docker://docker
       with:
          args: docker restart oracle
     - name: Create database
       run:  bash ./create_tables.sh
       shell: bash 
     - name: Build with Maven
       run: mvn -B test --file pom.xml

where the first lines of the create_tables.sh filer are:

export ORACLE_SID=FREE
export ORACLE_HOME=/opt/oracle/product/23ai/dbhomeFree
export ORAENV_ASK=NO
export PATH=$ORACLE_HOME/bin
$PATH/sqlplus -S my_user/password_i_should_change <<SQL
whenever sqlerror exit 2;
...

I have tried both with SID FREE and FREEPDB1, but I get the same error message line 5: /opt/oracle/product/23ai/dbhomeFree/bin/sqlplus: No such file or directory. Any idea?
Thanks!

UPDATE 2: following steps at https://github.com/gvenzl/setup-oracle-free:

name: Build and test of Java Project
 
on: [push]
 
jobs:
 test:
  runs-on: ubuntu-latest
  timeout-minutes: 6
  steps:
     - uses: actions/checkout@v4
     - uses: gvenzl/setup-oracle-free@v1
       with:
          app-user: myUser
          app-user-password: myPwd
          startup-scripts: ${{ github.workspace }}/scripts
     - name: Set up JDK 21
       uses: actions/setup-java@v1
       with:
         java-version: 21
     - name: Setup timezone
       uses: zcong1993/setup-timezone@master
       with:
          timezone: Europe/Madrid
     - name: Build with Maven
       run: mvn -B test --file pom.xml

I got the error:

Error: can only create exec sessions on running containers: container state improper

UPDATE3: Thank you very much again. That works with docker. The point is that I need to create a database with concrete tables and, later, connect to it from JDBC. It seems that, after creating a user/password the login is denied, using:

url=jdbc:oracle:thin:@localhost:1521:FREE
user=myUser
password=myPwd

Although I create the user/password in the workflow.yml, it seems that it does not work. I also try to create them in the init.sql file (I have tried both with FREE and FREEPDB1 service names), but with no success:

ALTER SESSION SET CONTAINER=FREE;
CREATE USER myUser IDENTIFIED BY myPwd QUOTA UNLIMITED ON USERS;
GRANT CONNECT, RESOURCE TO myUser ;
CREATE SCHEMA  AUTHORIZATION myUser ; 
ALTER SESSION SET CURRENT_SCHEMA = myUser;

CREATE TABLE ...

Do you have any idea? Thank you very much

20

Apparently, this isn’t possible with GHA service containers at the moment as the files from your repo will only be available after your checkout step whereas the service container will start before that. See this GitHub discussion How to mount file from repository to the service container’s volume? for more details on this.

There are some workarounds mentioned in there. The simple one would be to restart the service container after your checkout step. See this comment on the same thread.

Alternatively, you may run container in the workflow using docker run or use docker compose for services.


However, I found this https://github.com/gvenzl/setup-oracle-free action and it does everything you need. You don’t need to set up services yourself. It’s simpler and straightforward; and, is from the same author.

I’ve tested it on ubuntu-latest runner and this is working fine for me.

Here are the relevant workflow steps:

- name: Checkout
  uses: actions/checkout@v4

- name: Setup Oracle container
  uses: gvenzl/setup-oracle-free@v1
  with:
    container-runtime: docker
    app-user: app_user
    app-user-password: app_user_password
    setup-scripts: ${{ github.workspace }}/scripts

- name: Check Oracle container logs for errors
  run: |
    docker container ls
    docker container logs oracledb | tee -a /tmp/oracledb.log
    if grep 'ERROR' /tmp/oracledb.log >/dev/null; then
      echo "[ERR] Something went wrong!"
      echo "[ERR] See above logs for more details."
      exit 1
    fi

The checkout step should come first in the sequence of steps. For the input parameter setup-scripts, the respective directory should be available to be mounted as a volume.

Currently, the container run logs are not being dumped to stdout/stderr. That’s why I had to dump its logs to a file and filter those for any errors in a subsequent step.

Apart from that, according to the docs, the url in your configuration i.e.:

url=jdbc:oracle:thin:@localhost:1521:FREE

should be:

url=jdbc:oracle:thin:@localhost:1521/FREEPDB1

As mentioned under ORACLE_DATABASE env var docs, FREEPDB1 is created by default. FREEPDB1 is a service name, not an SID – observe the difference between : and / in the url.


Given above information, your create_database.sql script will look like this:

ALTER SESSION SET CONTAINER = FREEPDB1;
CREATE USER myUser IDENTIFIED BY myPwd QUOTA UNLIMITED ON USERS;

GRANT CONNECT, RESOURCE TO myUser;
GRANT CREATE TABLE TO myUser;
ALTER SESSION SET CURRENT_SCHEMA = myUser;

And, your complete .properties file will be:

url=jdbc:oracle:thin:@localhost:1521/FREEPDB1
user=myUser
password=myPwd
schema=myUser

Observe that the database username/password (myUser/myPwd) is different from the application one (app-user/app-user-name i.e. app_user/app_user_password).


Here are some miscellaneous points:

  • Update actions actions/checkout@v2 and actions/setup-java@v1 to their respective latest versions. In addition, you can configure dependabot to automate this. See Keeping your actions up to date with Dependabot for more details.

  • actions/setup-java supports caching of maven dependencies. You might want to use that to speed up your workflow.

  • https://github.com/zcong1993/setup-timezone has not been updated in a long time. You can simply set TZ env var instead to set the timezone.

    env:
      TZ: Europe/Madrid
    

    You can set it at workflow, job, or step level according to your use case.

Recognized by CI/CD Collective

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật