diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml new file mode 100644 index 00000000..5800d41e --- /dev/null +++ b/.github/workflows/docker-release.yml @@ -0,0 +1,63 @@ +# +name: Create and publish a Docker cdoc2-server-liquibase image + +# Configures this workflow to run every time release is created +on: + release: + types: [created] + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: cdoc2-server-liquibase + #IMAGE_NAME: ${REGISTRY}/${GITHUB_REPOSITORY_OWNER}/cdoc2-put-server:${TAG}-${GITHUB_SHA} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ github.actor }}/${{ env.IMAGE_NAME }} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + id: push + uses: docker/build-push-action@v5 + with: + context: server-db/src/main/resources/db + #file: server-db/src/main/resources/db/Dockerfile + push: true + tags: ${{ env.REGISTRY }}/${{ github.actor }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}-${{ github.sha }} + labels: ${{ steps.meta.outputs.labels }} + + # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)." + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + #subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-name: ${{ env.REGISTRY }}/${{ github.actor }}/${{ env.IMAGE_NAME }} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + diff --git a/README.md b/README.md index baa2822d..9f2639da 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,10 @@ See [getting-started.md](getting-started.md) and [admin-guide.md](admin-guide.md Download `cdoc2-put-server` and `cdoc2-get-server` images from [open-eid Container registry](https://github.com/orgs/open-eid/packages?ecosystem=container) -[ghcr.io login](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-with-a-personal-access-token-classic) +* See [cdoc2-gatling-tests/setup-load-testing](https://github.com/open-eid/cdoc2-gatling-tests/tree/master/setup-load-testing) for `docker run` examples +* See [cdoc2-java-ref-impl/test/config/server/docker-compose.yml](https://github.com/open-eid/cdoc2-java-ref-impl/blob/master/test/test/config/server/docker-compose.yml) for `docker compose` example -TODO: Configuring Docker images +To create `cdoc2` database required by `put-server` and `get-server` see [postgres.README.md](postgres.README.md) ## Releasing and versioning diff --git a/postgres.README.md b/postgres.README.md index be7606c9..d1b90e29 100644 --- a/postgres.README.md +++ b/postgres.README.md @@ -1,4 +1,4 @@ -Create postgres instance inside docker +## Create postgres instance inside docker ``` docker run --name cdoc2-psql -p 5432:5432 -e POSTGRES_DB=cdoc2 -e POSTGRES_PASSWORD=secret -d postgres @@ -6,4 +6,36 @@ docker run --name cdoc2-psql -p 5432:5432 -e POSTGRES_DB=cdoc2 -e POSTGRES_PASSW docker start cdoc2-psql docker stop cdoc2-psql ``` -#docker rm cdoc2-psql \ No newline at end of file +#docker rm cdoc2-psql + + +## Create cdoc2 database + +Download [cdoc2-server-liquibase](https://github.com/orgs/open-eid/packages?ecosystem=container) image +(version must match server version) that contains liquibase changeset files +specific to server version and create a `cdoc2` database. If database is running inside Docker, then +`--link` is required, so that liquibase container can connect to it. +``` +docker run --rm --link cdoc2-psql \ + --env DB_URL=jdbc:postgresql://cdoc2-psql/cdoc2 \ + --env DB_PASSWORD=secret \ + --env DB_USER=postgres \ + ghcr.io/jann0k/cdoc2-server-liquibase:v1.4.0-liquibase.4-2bf479fd63cdf4c7277fcbef799e3da801cf741f +``` + +or use standard liquibase command options: + +``` +docker run --rm --link cdoc2-psql \ +ghcr.io/jann0k/cdoc2-server-liquibase:v1.4.0-liquibase.4-2bf479fd63cdf4c7277fcbef799e3da801cf741f \ + --url jdbc:postgresql://cdoc2-psql/cdoc2 \ + --username=postgres \ + --password=secret \ + --defaultsFile=liquibase.properties \ +update +``` + +Can also be used to update DB running in other host by changing `--url`, `--username` and `--password` parameters. +Then `--link` is not required. + +More info https://hub.docker.com/r/liquibase/liquibase \ No newline at end of file diff --git a/server-db/src/main/resources/db/Dockerfile b/server-db/src/main/resources/db/Dockerfile index 3b47da05..f598f2cc 100644 --- a/server-db/src/main/resources/db/Dockerfile +++ b/server-db/src/main/resources/db/Dockerfile @@ -1,5 +1,8 @@ -# this file is used to build a docker image for upgrading the database in RIA infra -FROM nexus.riaint.ee:8500/liquibase/liquibase +# by default use docker.io as Docker registry, overwrite with +# --build-arg LIQUIBASE_IMAGE=custom.registry.io:8500/liquibase/liquibase +ARG LIQUIBASE_IMAGE=docker.io/liquibase/liquibase:4.29.2 +FROM $LIQUIBASE_IMAGE +USER liquibase WORKDIR /liquibase/changelog