0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

firebase-emulatorをDockerhubにpushしたメモ

Last updated at Posted at 2025-04-12

概要

前回 作成したFirebaseEmulatorをAzurePipelineで使いたかった。パイプラインでBDDまではうまく動かなかったが、パイプラインで動作はしそうだったので備忘を残しておく。

起動の永続性あたりが課題だろうか。。 2025.04.15 追記 docker-composeでできた。

この時点のコード

ソースコード

infra/local/firebase/bin/push_docker_hub.sh
#!/bin/bash

bin_dir=$(cd $(dirname $0) && pwd)

IMAGE_NAME=ubuntu24-firebase-tools

source $bin_dir/.env

docker login -u $DOCKER_USERNAME -p $DOCKER_TOKEN

cd $bin_dir/../docker && docker build -t $IMAGE_NAME .
docker tag $IMAGE_NAME $DOCKER_USERNAME/$IMAGE_NAME:latest
docker push $DOCKER_USERNAME/$IMAGE_NAME:latest
infra/local/firebase/bin/.env
export DOCKER_USERNAME=hoge
export DOCKER_TOKEN=fuga

※ここで利用するDOCKER_TOKENについては後述する

DockerhubにPush

./bin/container_build.sh
./bin/push_docker_hub.sh

DOCKER_TOKENについて

公式の手順で取得。

image.png

image.png

Pushするには Write 権限が必要
image.png

Azure Pipeline での設定

公式をみると、volumesが項目としてあるが、ここへのマウントはGitのコードのClone前に行われるので、事前にファイルは渡せない。
そこで、image内にあらかじめ必要なファイルをいれたコンテナを用意する必要があった。

packages/bdd-e2e-test/azure-pipeline.yml
resources:
  containers:
    - container: firebase
      image: docker.io/hibohiboo66/ubuntu24-firebase-tools:latest
      ports:
      - 9099:9099 # Firebase Authentication
      - 9005:9005 # Firebase login
      - 4000:4000 # Firebase UI
      command: firebase emulators:start
      workingDirectory: /opt/firebase

jobs:
  - job: bdd_test
    displayName: 'Run BDD E2E tests'
    pool:
      vmImage: 'ubuntu-latest'
    variables:
      CI_DATABASE_URL: 'postgres://postgres:postgres@127.0.0.1:5432/main'

    services:
      postgres:
        image: postgres:17.4-alpine
        ports:
          - 5432:5432
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: main
        options: >-
          --health-cmd="pg_isready"
          --health-interval=10s
          --health-timeout=5s
          --health-retries=5
      firebase: firebase
    steps:
      - checkout: self
      
      # 省略
      
      # 🕐 Backend / Frontend の起動待ち(適宜 curl でチェック)
      - script: |
          echo "Waiting for frontend server..."
          for i in {1..20}; do
            if curl -s http://localhost:5173 > /dev/null; then
              echo "Frontend server is up."
              break
            fi
            sleep 2
          done
           echo "Waiting for backend server..."
          for i in {1..20}; do
            if curl -s http://localhost:8787 > /dev/null; then
              echo "Backend server is up."
              break
            fi
            sleep 2
          done
          echo "Waiting for firebase auth server..."
          for i in {1..20}; do
            if curl -s http://localhost:9099 > /dev/null; then
              echo "Firebase Auth is up."
              break
            fi
            sleep 2
          done
          echo "Waiting for firebase login server..."
          for i in {1..20}; do
            if curl -s http://localhost:9005 > /dev/null; then
              echo "Firebase Login is up."
              break
            fi
            sleep 2
          done
        displayName: 'Wait for servers to start'

パイプラインの結果

起動させることはできたが、E2Eは失敗した。

postgresと違って、通信ができない模様。

image.png

image.png

postgresqlと同じようにヘルスチェックを入れようとしたがうまく動かず。。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?