diff --git a/.github/workflows/build_push.yml b/.github/workflows/build_push.yml new file mode 100644 index 00000000..a8272b7f --- /dev/null +++ b/.github/workflows/build_push.yml @@ -0,0 +1,31 @@ +name: build and push docker images +on: + push: + branches: + - main + pull_request: + branches: + - "*" +env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Login to GHCR (GitHub Packages) + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build Server image + run: app/server/docker/build + - name: Build Proxy image + run: proxy/docker/build + - name: Docker smoke test + run: scripts/docker_smoke_test + - name: Push Server image branch ${{ env.BRANCH_NAME }} + run: app/server/docker/push + - name: Push Proxy image branch ${{ env.BRANCH_NAME }} + run: proxy/docker/push diff --git a/.github/workflows/jestCI.yml b/.github/workflows/jestCI.yml index 86a4cd52..26b3af4c 100644 --- a/.github/workflows/jestCI.yml +++ b/.github/workflows/jestCI.yml @@ -49,6 +49,12 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Login to GHCR (GitHub Packages) + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: @@ -63,6 +69,7 @@ jobs: - name: run all components working-directory: . run: ./scripts/run_test server-only + - name: Run unit and integration tests run: npm run test - name: stop all components diff --git a/.github/workflows/playwrightCI.yml b/.github/workflows/playwrightCI.yml index 98b3723c..ab69b275 100644 --- a/.github/workflows/playwrightCI.yml +++ b/.github/workflows/playwrightCI.yml @@ -20,6 +20,12 @@ jobs: node-version: [20.x] steps: - uses: actions/checkout@v4 + - name: Login to GHCR (GitHub Packages) + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: diff --git a/README.md b/README.md index 0d155c73..cff99e9f 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Bring down the app with Docker images are built on CI using `./proxy/docker/build`, `./app/server/docker/build`. If you want to generate them from changed local sources you can run those same scripts locally to build images. -To target a branch of `beebop_py`, set `API_BRANCH` in `scripts/common`. +To target a branch of `beebop_py`, set `API_IMAGE` in `scripts/common`. When running locally in docker, the backend is serving from `beebop_beebop-server_1`, and the front end from the proxy container `beebop_proxy_1`. diff --git a/app/server/docker/common b/app/server/docker/common index 58dc297e..fc1c3cf8 100755 --- a/app/server/docker/common +++ b/app/server/docker/common @@ -1,25 +1,18 @@ #!/usr/bin/env bash set -e +REGISTRY=ghcr.io PACKAGE_ROOT=$(realpath $HERE/..) PACKAGE_NAME=beebop-server -PACKAGE_ORG=mrcide +PACKAGE_ORG=bacpop -# Buildkite doesn't check out a full history from the remote (just the -# single commit) so you end up with a detached head and git rev-parse -# doesn't work -if [ "$BUILDKITE" = "true" ]; then - GIT_SHA=${BUILDKITE_COMMIT:0:7} +GIT_SHA=$(git -C "$PACKAGE_ROOT" rev-parse --short=7 HEAD) +if [[ -v "BRANCH_NAME" ]]; then + GIT_BRANCH=${BRANCH_NAME} else - GIT_SHA=$(git -C "$PACKAGE_ROOT" rev-parse --short=7 HEAD) + GIT_BRANCH=$(git symbolic-ref --short HEAD) fi -if [ "$BUILDKITE" = "true" ]; then - GIT_BRANCH=$BUILDKITE_BRANCH -else - GIT_BRANCH=$(git -C "$PACKAGE_ROOT" symbolic-ref --short HEAD) -fi - -TAG_SHA="${PACKAGE_ORG}/${PACKAGE_NAME}:${GIT_SHA}" -TAG_BRANCH="${PACKAGE_ORG}/${PACKAGE_NAME}:${GIT_BRANCH}" -TAG_LATEST="${PACKAGE_ORG}/${PACKAGE_NAME}:latest" \ No newline at end of file +TAG_SHA="${REGISTRY}/${PACKAGE_ORG}/${PACKAGE_NAME}:${GIT_SHA}" +TAG_BRANCH="${REGISTRY}/${PACKAGE_ORG}/${PACKAGE_NAME}:${GIT_BRANCH}" +TAG_LATEST="${REGISTRY}/${PACKAGE_ORG}/${PACKAGE_NAME}:latest" \ No newline at end of file diff --git a/app/server/docker/push b/app/server/docker/push index 3fecfecb..eb15fd75 100755 --- a/app/server/docker/push +++ b/app/server/docker/push @@ -4,9 +4,6 @@ set -e HERE=$(dirname $0) . $HERE/common -# In case we switch agents between steps -[ ! -z $(docker images -q $TAG_SHA) ] || docker pull $TAG_SHA - docker tag $TAG_SHA $TAG_BRANCH docker push $TAG_BRANCH diff --git a/buildkite/pipeline.yml b/buildkite/pipeline.yml deleted file mode 100644 index 033737e4..00000000 --- a/buildkite/pipeline.yml +++ /dev/null @@ -1,20 +0,0 @@ -steps: - - label: ":whale::vue: Build Server" - command: app/server/docker/build - - - label: ":whale::nginx: Build Proxy" - command: proxy/docker/build - - - wait - - - label: ":shipit: Push Server images" - command: app/server/docker/push - - - label: ":shipit: Push Proxy images" - command: proxy/docker/push - - - wait - - - label: ":mag: Docker smoke test" - command: scripts/docker_smoke_test - diff --git a/docker-compose.yml b/docker-compose.yml index 48592ec9..262fff6a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3" services: proxy: - image: mrcide/beebop-proxy:${GIT_SHA} + image: ghcr.io/bacpop/beebop-proxy:${GIT_SHA} depends_on: - beebop-server ports: @@ -10,12 +10,12 @@ services: command: $HOST beebop-server beebop-server: - image: mrcide/beebop-server:${GIT_SHA} + image: ghcr.io/bacpop/beebop-server:${GIT_SHA} depends_on: - beebop-py-api - beebop-redis beebop-py-api: - image: mrcide/beebop-py:${API_BRANCH} + image: ghcr.io/bacpop/beebop-py:${API_IMAGE} depends_on: - beebop-redis volumes: @@ -26,7 +26,7 @@ services: beebop-redis: image: redis:5.0 beebop-py-worker: - image: mrcide/beebop-py:${API_BRANCH} + image: ghcr.io/bacpop/beebop-py:${API_IMAGE} depends_on: - beebop-redis command: diff --git a/proxy/bin/reverse-proxy b/proxy/bin/reverse-proxy index 95755e5e..ef93da52 100755 --- a/proxy/bin/reverse-proxy +++ b/proxy/bin/reverse-proxy @@ -6,7 +6,7 @@ if [ "$#" -eq 2 ]; then export SERVER_NAME=$2 else echo "Usage: " - echo "e.g. docker run ... mrcide/beebop-proxy:master localhost beebop-server" + echo "e.g. docker run ... ghcr.io/bacpop/beebop-proxy:master localhost beebop-server" exit 1 fi diff --git a/proxy/docker/build b/proxy/docker/build index 1e6fb459..3b91155b 100755 --- a/proxy/docker/build +++ b/proxy/docker/build @@ -11,4 +11,4 @@ docker build --pull \ # We always push the SHA tagged versions, for debugging if the tests # after this step fail -docker push $TAG_SHA +docker push $TAG_SHA \ No newline at end of file diff --git a/proxy/docker/common b/proxy/docker/common index db4bd595..4cfeec6f 100755 --- a/proxy/docker/common +++ b/proxy/docker/common @@ -1,25 +1,19 @@ #!/usr/bin/env bash set -e +REGISTRY=ghcr.io PACKAGE_ROOT=$(realpath $HERE/..) PACKAGE_NAME=beebop-proxy -PACKAGE_ORG=mrcide +PACKAGE_ORG=bacpop -# Buildkite doesn't check out a full history from the remote (just the -# single commit) so you end up with a detached head and git rev-parse -# doesn't work -if [ "$BUILDKITE" = "true" ]; then - GIT_SHA=${BUILDKITE_COMMIT:0:7} +GIT_SHA=$(git -C "$PACKAGE_ROOT" rev-parse --short=7 HEAD) +if [[ -v "BRANCH_NAME" ]]; then + GIT_BRANCH=${BRANCH_NAME} else - GIT_SHA=$(git -C "$PACKAGE_ROOT" rev-parse --short=7 HEAD) + GIT_BRANCH=$(git symbolic-ref --short HEAD) fi -if [ "$BUILDKITE" = "true" ]; then - GIT_BRANCH=$BUILDKITE_BRANCH -else - GIT_BRANCH=$(git -C "$PACKAGE_ROOT" symbolic-ref --short HEAD) -fi -TAG_SHA="${PACKAGE_ORG}/${PACKAGE_NAME}:${GIT_SHA}" -TAG_BRANCH="${PACKAGE_ORG}/${PACKAGE_NAME}:${GIT_BRANCH}" -TAG_LATEST="${PACKAGE_ORG}/${PACKAGE_NAME}:latest" +TAG_SHA="${REGISTRY}/${PACKAGE_ORG}/${PACKAGE_NAME}:${GIT_SHA}" +TAG_BRANCH="${REGISTRY}/${PACKAGE_ORG}/${PACKAGE_NAME}:${GIT_BRANCH}" +TAG_LATEST="${REGISTRY}/${PACKAGE_ORG}/${PACKAGE_NAME}:latest" diff --git a/proxy/docker/push b/proxy/docker/push index d47dc850..d414a465 100755 --- a/proxy/docker/push +++ b/proxy/docker/push @@ -4,8 +4,6 @@ set -e HERE=$(dirname $0) . $HERE/common -# In case we switch agents between steps -[ ! -z $(docker images -q $TAG_SHA) ] || docker pull $TAG_SHA docker tag $TAG_SHA $TAG_BRANCH docker push $TAG_BRANCH diff --git a/scripts/common b/scripts/common index c57470a2..e84a2174 100755 --- a/scripts/common +++ b/scripts/common @@ -1,2 +1,2 @@ #!/usr/bin/env bash -export API_BRANCH="main" +export API_IMAGE="main" diff --git a/scripts/run_dependencies b/scripts/run_dependencies index 282b2de7..bec44191 100755 --- a/scripts/run_dependencies +++ b/scripts/run_dependencies @@ -14,7 +14,7 @@ PORT=5000 docker volume create $VOLUME docker run --rm -v $VOLUME:/beebop/storage \ --pull always \ - mrcide/beebop-py:$API_BRANCH \ + ghcr.io/bacpop/beebop-py:$API_IMAGE \ ./scripts/download_databases --refs # remove --refs to download all databases docker network create $NETWORK > /dev/null || /bin/true @@ -23,7 +23,7 @@ docker run -d --rm --name $NAME_WORKER --network=$NETWORK \ --pull always \ --env=REDIS_HOST="$NAME_REDIS" \ -v $VOLUME:/beebop/storage \ - mrcide/beebop-py:$API_BRANCH rqworker + ghcr.io/bacpop/beebop-py:$API_IMAGE rqworker docker run -d --rm --name $NAME_API --network=$NETWORK \ --pull always \ @@ -32,4 +32,4 @@ docker run -d --rm --name $NAME_API --network=$NETWORK \ --env=DBS_LOCATION="./storage/dbs" \ -v $VOLUME:/beebop/storage \ -p $PORT:5000 \ - mrcide/beebop-py:$API_BRANCH \ No newline at end of file + ghcr.io/bacpop/beebop-py:$API_IMAGE \ No newline at end of file diff --git a/scripts/run_docker b/scripts/run_docker index a1e7e9d1..c2763c2c 100755 --- a/scripts/run_docker +++ b/scripts/run_docker @@ -20,5 +20,5 @@ docker cp app/server/src/resources/config.json beebop-beebop-server-1:/app/src/r docker cp proxy/ssl/dhparam.pem beebop-proxy-1:/run/proxy/ docker cp proxy/$SSL_PATH/certificate.pem beebop-proxy-1:/run/proxy/ docker cp proxy/$SSL_PATH/key.pem beebop-proxy-1:/run/proxy/ -docker run --rm -v beebop_beebop-storage:/beebop/storage mrcide/beebop-py:$API_BRANCH \ +docker run --rm -v beebop_beebop-storage:/beebop/storage ghcr.io/bacpop/beebop-py:$API_IMAGE \ ./scripts/download_databases --refs